[pygobject] Add tests for priority argument of idle_add/timeout_add



commit 2357f4a0237feabcf6886f2a448aa3f42f6781b9
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Oct 24 09:14:57 2012 +0200

    Add tests for priority argument of idle_add/timeout_add
    
    There is a potential to treat the priority as user data in a call like
    "GLib.idle_add(cb, GLib.PRIORITY_HIGH)". The current static bindings force
    using a keyword argument for the priority (but silently ignore it if you
    specify both userdata and priority as a positional argument).
    
    Test the correct handling of priority as well.

 tests/test_source.py |   63 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/tests/test_source.py b/tests/test_source.py
index 48d9460..cca4a94 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -189,7 +189,9 @@ class TestUserData(unittest.TestCase):
 
         def cb():
             ml.quit()
-        GLib.idle_add(cb)
+        id = GLib.idle_add(cb)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_DEFAULT_IDLE)
         ml.run()
 
     def test_timeout_no_data(self):
@@ -197,7 +199,9 @@ class TestUserData(unittest.TestCase):
 
         def cb():
             ml.quit()
-        GLib.timeout_add(50, cb)
+        id = GLib.timeout_add(50, cb)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_DEFAULT)
         ml.run()
 
     def test_idle_data(self):
@@ -207,7 +211,9 @@ class TestUserData(unittest.TestCase):
             data['called'] = True
             ml.quit()
         data = {}
-        GLib.idle_add(cb, data)
+        id = GLib.idle_add(cb, data)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_DEFAULT_IDLE)
         ml.run()
         self.assertTrue(data['called'])
 
@@ -218,9 +224,58 @@ class TestUserData(unittest.TestCase):
             data['called'] = True
             ml.quit()
         data = {}
-        GLib.timeout_add(50, cb, data)
+        id = GLib.timeout_add(50, cb, data)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_DEFAULT)
         ml.run()
         self.assertTrue(data['called'])
 
+    def test_idle_no_data_priority(self):
+        ml = GLib.MainLoop()
+
+        def cb():
+            ml.quit()
+        id = GLib.idle_add(cb, priority=GLib.PRIORITY_HIGH)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_HIGH)
+        ml.run()
+
+    def test_timeout_no_data_priority(self):
+        ml = GLib.MainLoop()
+
+        def cb():
+            ml.quit()
+        id = GLib.timeout_add(50, cb, priority=GLib.PRIORITY_HIGH)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_HIGH)
+        ml.run()
+
+    def test_idle_data_priority(self):
+        ml = GLib.MainLoop()
+
+        def cb(data):
+            data['called'] = True
+            ml.quit()
+        data = {}
+        id = GLib.idle_add(cb, data, priority=GLib.PRIORITY_HIGH)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_HIGH)
+        ml.run()
+        self.assertTrue(data['called'])
+
+    def test_timeout_data_priority(self):
+        ml = GLib.MainLoop()
+
+        def cb(data):
+            data['called'] = True
+            ml.quit()
+        data = {}
+        id = GLib.timeout_add(50, cb, data, priority=GLib.PRIORITY_HIGH)
+        self.assertEqual(ml.get_context().find_source_by_id(id).priority,
+                         GLib.PRIORITY_HIGH)
+        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]