summaryrefslogtreecommitdiff
path: root/tests/test_error.py
diff options
context:
space:
mode:
authorGarrett Regier <garrett.regier@riftio.com>2015-06-03 07:06:40 -0700
committerGarrett Regier <garrett.regier@riftio.com>2015-09-22 13:36:18 -0700
commit40bba555c835cf53d6aa2645329631e6abe57e6c (patch)
treeef46abbbbee02c1d9df73acfe33d8c2ccd8364c3 /tests/test_error.py
parentea75a89a7d2bdabc7a29f7f20f792211765f2ac7 (diff)
downloadpygobject-40bba555c835cf53d6aa2645329631e6abe57e6c.tar.gz
Support throwing exceptions in closures
This allows exceptions raised in vfunc implemntations and callbacks to be turned into GErrors. NOTE: this requires matchs in https://bugzilla.gnome.org/show_bug.cgi?id=729543 thus we must bump the GI req once they are commited. https://bugzilla.gnome.org/show_bug.cgi?id=710671
Diffstat (limited to 'tests/test_error.py')
-rw-r--r--tests/test_error.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_error.py b/tests/test_error.py
index baccef5c..f5a89cec 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -64,6 +64,14 @@ class TestType(unittest.TestCase):
self.assertTrue(issubclass(GLib.Error, RuntimeError))
+class ObjectWithVFuncException(GIMarshallingTests.Object):
+ def do_vfunc_meth_with_err(self, x):
+ if x == 42:
+ return True
+
+ raise GLib.Error('unexpected value %d' % x, 'mydomain', 42)
+
+
class TestMarshalling(unittest.TestCase):
def test_array_in_crash(self):
# Previously there was a bug in invoke, in which C arrays were unwrapped
@@ -111,6 +119,20 @@ class TestMarshalling(unittest.TestCase):
self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
+ def test_vfunc_no_exception(self):
+ obj = ObjectWithVFuncException()
+ self.assertTrue(obj.vfunc_meth_with_error(42))
+
+ def test_vfunc_gerror_exception(self):
+ obj = ObjectWithVFuncException()
+ with self.assertRaises(GLib.Error) as context:
+ obj.vfunc_meth_with_error(-1)
+
+ e = context.exception
+ self.assertEqual(e.message, 'unexpected value -1')
+ self.assertEqual(e.domain, 'mydomain')
+ self.assertEqual(e.code, 42)
+
if __name__ == '__main__':
unittest.main()