diff options
Diffstat (limited to 'tests/glibext/strbuilder.py')
-rw-r--r-- | tests/glibext/strbuilder.py | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/tests/glibext/strbuilder.py b/tests/glibext/strbuilder.py index ced405e..72fd5c2 100644 --- a/tests/glibext/strbuilder.py +++ b/tests/glibext/strbuilder.py @@ -1,4 +1,6 @@ +import gi + from chrysacase import ChrysalideTestCase from gi.repository import GObject from pychrysalide.glibext import StringBuilder @@ -8,22 +10,31 @@ class TestStringBuilder(ChrysalideTestCase): """Test cases for pychrysalide.glibext.StringBuilder.""" - def testStringBuilderCreation(self): + def ZZZtestStringBuilderCreation(self): """Create objects with StringBuilder interface.""" with self.assertRaisesRegex(NotImplementedError, 'StringBuilder can not be constructed'): - sc = StringBuilder() + sb = StringBuilder() + - class NewStringBuilderImplem(GObject.Object, StringBuilder): + class NewStringBuilderImplem(gi._gi.GObject, StringBuilder): pass - nsi = NewStringBuilderImplem() + nsb = NewStringBuilderImplem() + + self.assertIsNotNone(nsb) + + + class NewStringBuilderImplem2(GObject.Object, StringBuilder): + pass - self.assertIsNotNone(nsi) + nsb2 = NewStringBuilderImplem() + self.assertIsNotNone(nsb2) - def testStringBuilderMethods(self): + + def ZZZtestStringBuilderMethods(self): """Test the StringBuilder methods.""" class BasicStringBuilderImplem(GObject.Object, StringBuilder): @@ -42,3 +53,62 @@ class TestStringBuilder(ChrysalideTestCase): self.assertEqual(sb.to_string(), desc) self.assertEqual(str(sb), desc) self.assertEqual(f'{sb}', desc) + + + def testStringBuilderExceptions(self): + """Raise exceptions from the StringBuilder interface as expected.""" + + + class BadStringBuilderImplem(GObject.Object, StringBuilder): + pass + + obj = BadStringBuilderImplem() + + + with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_to_string'"): + + s = str(obj) + + + class BadStringBuilderImplem2(GObject.Object, StringBuilder): + + def _to_string(self, flags=0): + return 0xcafe + + obj2 = BadStringBuilderImplem2() + + + with self.assertRaisesRegex(TypeError, 'object description has to get provided as an UTF-8 string value'): + + s = str(obj2) + + + class BadStringBuilderImplem3a(GObject.Object, StringBuilder): + + def _to_string(self, flags=0): + return 'desc' + + class BadStringBuilderImplem3b(BadStringBuilderImplem3a, StringBuilder): + + def _to_string(self, flags=0): + return self.parent_to_string() + + obj3 = BadStringBuilderImplem3b() + + + with self.assertRaisesRegex(RuntimeError, 'object parent is not a native type'): + + s = str(obj3) + + + class BadStringBuilderImplem4(GObject.Object, StringBuilder): + + def _to_string(self, flags=0): + raise Exception('error') + + obj4 = BadStringBuilderImplem4() + + + with self.assertRaisesRegex(Exception, 'error'): + + s = str(obj4) |