From 0a99d55f938547c419891ecde631bb77601dd8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Mon, 19 Aug 2024 09:50:51 +0200 Subject: [PATCH] tests: Add strip_console_codes test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukáš Doktor --- tests/test_utils.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..4933c06 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,36 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2024 +# Author: Lukas Doktor + +# selftests pylint: disable=C0111,C0111 + +import unittest + +from aexpect.utils import astring + + +class Astring(unittest.TestCase): + + def test_strip_console_codes(self): + """ + Try various strip_console_codes + """ + strip = astring.strip_console_codes + self.assertEqual("simple color test", + strip("simple\x1b[33;1m color \x1b[0mtest")) + self.assertEqual("[33;1mstarts with code", "[33;1mstarts with code") + self.assertEqual("ends with escape\x1b", "ends with escape\x1b") + + +if __name__ == '__main__': + unittest.main()