[pygobject] Add tests for idle_add()/timeout_add with and without user data



commit 0bc0b55be0dae7528c2fc7439d672ad4e417335d
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Oct 24 08:33:49 2012 +0200

    Add tests for idle_add()/timeout_add with and without user data
    
    This is implicitly spread over various test cases, but let's test it explicitly
    to ensure that the behaviour stays consistent when moving this to GI.

 tests/test_source.py |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_source.py b/tests/test_source.py
index 0d5c750..df95e7a 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -183,5 +183,40 @@ class TestSource(unittest.TestCase):
         GLib.Idle()
 
 
+class TestUserData(unittest.TestCase):
+    def test_idle_no_data(self):
+        ml = GLib.MainLoop()
+        def cb():
+            ml.quit()
+        GLib.idle_add(cb)
+        ml.run()
+
+    def test_timeout_no_data(self):
+        ml = GLib.MainLoop()
+        def cb():
+            ml.quit()
+        GLib.timeout_add(50, cb)
+        ml.run()
+
+    def test_idle_data(self):
+        ml = GLib.MainLoop()
+        def cb(data):
+            data['called'] = True
+            ml.quit()
+        data = {}
+        GLib.idle_add(cb, data)
+        ml.run()
+        self.assertTrue(data['called'])
+
+    def test_timeout_data(self):
+        ml = GLib.MainLoop()
+        def cb(data):
+            data['called'] = True
+            ml.quit()
+        data = {}
+        GLib.timeout_add(50, cb, data)
+        ml.run()
+        self.assertTrue(data['called'])
+
 if __name__ == '__main__':
     unittest.main()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]