summaryrefslogtreecommitdiffstats
path: root/tests/test_gi.py
diff options
context:
space:
mode:
authorZach Goldberg <zach@zachgoldberg.com>2010-04-17 09:17:14 -0400
committerTomeu Vizoso <tomeu@sugarlabs.org>2010-04-17 11:00:39 -0400
commit610dd1eec87fab5c8c3badb4d104cba74477c745 (patch)
tree040b02f66d861bb35cd6aedfa2bb1f89e13c465d /tests/test_gi.py
parenta34cb9f0038a6c89e5e6c5f7761d48a5a833044f (diff)
downloadpygi-610dd1eec87fab5c8c3badb4d104cba74477c745.tar.gz
pygi-610dd1eec87fab5c8c3badb4d104cba74477c745.tar.xz
pygi-610dd1eec87fab5c8c3badb4d104cba74477c745.zip
Implementation callback support with scoping and basic argument support.
This patch was originally written by Zach Goldberg <zach@zachgoldberg.com> with modifications and review by Simon van der Linden <svdlinden@src.gnome.org> and Colin Walters <walters@verbum.org>. This impementation enforces the assumption that any one function signature can only have one (callback, userdata, destronotify) tuple. This allows us to move callback creation into the actual function invoke pipeline and also to keep just one destroy notify callback around, vastly simplifying the code. https://bugzilla.gnome.org/show_bug.cgi?id=603095
Diffstat (limited to 'tests/test_gi.py')
-rw-r--r--tests/test_gi.py64
1 files changed, 63 insertions, 1 deletions
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 9b9a849..a9076b6 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,7 +12,7 @@ from datetime import datetime
import sys
sys.path.insert(0, "../")
-from gi.repository import GIMarshallingTests
+from gi.repository import GIMarshallingTests, Everything
CONSTANT_UTF8 = "const \xe2\x99\xa5 utf8"
@@ -1399,3 +1399,65 @@ class TestOverrides(unittest.TestCase):
object_ = GIMarshallingTests.overrides_object_return()
self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
+
+
+class TestCallbacks(unittest.TestCase):
+ called = False
+ def testCallback(self):
+ TestCallbacks.called = False
+ def callback():
+ TestCallbacks.called = True
+
+ Everything.test_simple_callback(callback)
+ self.assertTrue(TestCallbacks.called)
+
+ def testCallbackException(self):
+ """
+ This test ensures that we get errors from callbacks correctly
+ and in particular that we do not segv when callbacks fail
+ """
+ def callback():
+ x = 1 / 0
+
+ try:
+ Everything.test_simple_callback(callback)
+ except ZeroDivisionError:
+ pass
+
+ def testDoubleCallbackException(self):
+ """
+ This test ensures that we get errors from callbacks correctly
+ and in particular that we do not segv when callbacks fail
+ """
+ def badcallback():
+ x = 1 / 0
+
+ def callback():
+ GIMarshallingTests.boolean_return_true()
+ GIMarshallingTests.boolean_return_false()
+ Everything.test_simple_callback(badcallback())
+
+ try:
+ Everything.test_simple_callback(callback)
+ except ZeroDivisionError:
+ pass
+
+ def testReturnValueCallback(self):
+ TestCallbacks.called = False
+ def callback():
+ TestCallbacks.called = True
+ return 44
+
+ self.assertEquals(Everything.test_callback(callback), 44)
+ self.assertTrue(TestCallbacks.called)
+
+ def testCallbackAsync(self):
+ TestCallbacks.called = False
+ def callback(foo):
+ TestCallbacks.called = True
+ return foo
+
+ Everything.test_callback_async(callback, 44);
+ i = Everything.test_callback_thaw_async();
+ self.assertEquals(44, i);
+ self.assertTrue(TestCallbacks.called)