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)