diff options
Diffstat (limited to 'tests/glibext/strbuilder.py')
-rw-r--r-- | tests/glibext/strbuilder.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/glibext/strbuilder.py b/tests/glibext/strbuilder.py new file mode 100644 index 0000000..ced405e --- /dev/null +++ b/tests/glibext/strbuilder.py @@ -0,0 +1,44 @@ + +from chrysacase import ChrysalideTestCase +from gi.repository import GObject +from pychrysalide.glibext import StringBuilder + + +class TestStringBuilder(ChrysalideTestCase): + """Test cases for pychrysalide.glibext.StringBuilder.""" + + + def testStringBuilderCreation(self): + """Create objects with StringBuilder interface.""" + + with self.assertRaisesRegex(NotImplementedError, 'StringBuilder can not be constructed'): + + sc = StringBuilder() + + class NewStringBuilderImplem(GObject.Object, StringBuilder): + pass + + nsi = NewStringBuilderImplem() + + self.assertIsNotNone(nsi) + + + def testStringBuilderMethods(self): + """Test the StringBuilder methods.""" + + class BasicStringBuilderImplem(GObject.Object, StringBuilder): + + def __init__(self, desc): + super().__init__() + self._desc = desc + + def _to_string(self, flags=0): + return self._desc + + desc = 'simple_desc' + + sb = BasicStringBuilderImplem(desc) + + self.assertEqual(sb.to_string(), desc) + self.assertEqual(str(sb), desc) + self.assertEqual(f'{sb}', desc) |