dbus/test/python test-client.py,1.11,1.12 test-service.py,1.5,1.6

Robert McQueen robot101 at freedesktop.org
Fri Nov 4 04:18:02 PST 2005


Update of /cvs/dbus/dbus/test/python
In directory gabe:/tmp/cvs-serv18708/test/python

Modified Files:
	test-client.py test-service.py 
Log Message:
2005-11-04  Robert McQueen  <robot101 at debian.org>

        * python/dbus_bindings.pyx, test/python/test-client.py: Fix
        marshalling of boolean values. Add some booleans to the values in
        the test client.

        * python/decorators.py, python/service.py: Add an 'async_callbacks'
        argument to the dbus.service.method decorator, which allows you to
        name arguments to take two callback functions for replying with
        return values or an exception.

        * test/python/test-client.py, test/python/test-service.py: Add test
        case using asynchronous method reply functions, both return values and
        errors, and from within both the function itself and from a mainloop
        callback.

        * python/decorators.py, python/service.py: Perform checking that the
        number of method/signal arguments matches the number of types in the
        signature at class loading time, not when you first introspect the
        class.

        * python/service.py: Remove debug print left by the last commit.


Index: test-client.py
===================================================================
RCS file: /cvs/dbus/dbus/test/python/test-client.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- test-client.py	3 Nov 2005 21:47:31 -0000	1.11
+++ test-client.py	4 Nov 2005 12:18:00 -0000	1.12
@@ -29,6 +29,7 @@
                  (1,2,3), (1,), (1,"2",3), ("2", "what"), ("you", 1.2),
                  {1:"a", 2:"b"}, {"a":1, "b":2}, #{"a":(1,"B")},
                  {1:1.1, 2:2.2}, [[1,2,3],[2,3,4]], [["a","b"],["c","d"]],
+                 True, False,
                  #([1,2,3],"c", 1.2, ["a","b","c"], {"a": (1,"v"), "b": (2,"d")})
                  ]
 
@@ -153,6 +154,21 @@
         print "CheckInheritance returned %s" % ret
         self.assert_(ret, "overriding CheckInheritance from TestInterface failed")
 
+    def testAsyncMethods(self):
+        print "\n********* Testing asynchronous method implementation *******"
+        for (async, fail) in ((False, False), (False, True), (True, False), (True, True)):
+            try:
+                val = ('a', 1, False, [1,2], {1:2})
+                print "calling AsynchronousMethod with %s %s %s" % (async, fail, val)
+                ret = self.iface.AsynchronousMethod(async, fail, val)
+            except Exception, e:
+                print "%s:\n%s" % (e.__class__, e)
+                self.assert_(fail)
+            else:
+                self.assert_(not fail)
+                print val, ret
+                self.assert_(val == ret)
+
 class TestDBusPythonToGLibBindings(unittest.TestCase):
     def setUp(self):
         self.bus = dbus.SessionBus()

Index: test-service.py
===================================================================
RCS file: /cvs/dbus/dbus/test/python/test-service.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test-service.py	29 Oct 2005 22:41:07 -0000	1.5
+++ test-service.py	4 Nov 2005 12:18:00 -0000	1.6
@@ -80,6 +80,22 @@
     def CheckInheritance(self):
         return True
 
+    @dbus.service.method('org.freedesktop.DBus.TestSuiteInterface', in_signature='bbv', out_signature='v', async_callbacks=('return_cb', 'error_cb'))
+    def AsynchronousMethod(self, async, fail, variant, return_cb, error_cb):
+        try:
+            if async:
+                gobject.timeout_add(500, self.AsynchronousMethod, False, fail, variant, return_cb, error_cb)
+                return
+            else:
+                if fail:
+                    raise RuntimeError
+                else:
+                    return_cb(variant)
+
+                return False # do not run again
+        except Exception, e:
+            error_cb(e)
+
 session_bus = dbus.SessionBus()
 name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
 object = TestObject(name)



More information about the dbus-commit mailing list