Since this thing is on the innerwebs I suppose it should have a
[python_utils.git] / tests / string_utils_test.py
index 0472daaccaf9a525794df24e79c8ae5f923898f0..c111b64f9bbb934a1fcb4ae2b8133a085ad62edd 100755 (executable)
@@ -1,17 +1,19 @@
 #!/usr/bin/env python3
 
+# © Copyright 2021-2022, Scott Gasch
+
+"""string_utils unittest."""
+
 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(""))
@@ -130,7 +132,7 @@ class TestStringUtils(unittest.TestCase):
         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)
@@ -180,6 +182,12 @@ class TestStringUtils(unittest.TestCase):
         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)()