import unittest
-from ansi import fg, bg, reset
import bootstrap
import string_utils as su
-
import unittest_utils as uu
+from ansi import bg, fg, reset
@uu.check_all_methods_for_perf_regressions()
class TestStringUtils(unittest.TestCase):
-
def test_is_none_or_empty(self):
self.assertTrue(su.is_none_or_empty(None))
self.assertTrue(su.is_none_or_empty(""))
s = f' {fg("red")} this is a test {bg("white")} this is a test {reset()} '
self.assertEqual(
su.strip_escape_sequences(s),
- ' this is a test this is a test '
+ ' this is a test this is a test ',
)
s = ' this is another test '
self.assertEqual(su.strip_escape_sequences(s), s)
self.assertFalse(su.is_snake_case('thisIsATest'))
self.assertTrue(su.is_snake_case('this_is_a_test'))
+ def test_sprintf_context(self):
+ with su.SprintfStdout() as buf:
+ print("This is a test.")
+ print("This is another one.")
+ self.assertEqual('This is a test.\nThis is another one.\n', buf())
+
if __name__ == '__main__':
bootstrap.initialize(unittest.main)()