summaryrefslogtreecommitdiff
path: root/tests/glibext/strbuilder.py
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-12-10 12:27:25 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-12-10 12:27:25 (GMT)
commit01c72e2f339f9cda8a8f08748ed591276a7aaa99 (patch)
treecd5e12b3d0deb7f5fd4f27ebf4d2de4b9a1a25c6 /tests/glibext/strbuilder.py
parenta07282d2f96ad99c9e280f139a63757b34a23695 (diff)
Implement a toString()-like interface.
Diffstat (limited to 'tests/glibext/strbuilder.py')
-rw-r--r--tests/glibext/strbuilder.py44
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)