dbus/test/python test-client.py,1.13,1.14 test-service.py,1.6,1.7

Robert McQueen robot101 at freedesktop.org
Mon Nov 7 07:31:32 PST 2005


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

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

	* python/decorators.py: Change emit_signal function to use the
	signature annotation of the signal when marhsalling the arguments from
	the service. Fix a bug where the code checking signature length
	against argument length referenced the wrong variable.

	* python/introspect_parser.py: Avoid adding the type signature of
	signal arguments to any methods which occur after them in the
	introspection data (!) by making the parser a little more careful
	about its current state.

	* python/service.py: Remove debug prints from last commit (again :D).

	* test/python/test-client.py, test/python/test-service.py: Add test
	signals with signature decorators to test the strict marshalling code
	gives errors at the right time. Could do with checking the signals
	actually get emitted too, given that the test does nothing with
	signals at the moment...

Index: test-client.py
===================================================================
RCS file: /cvs/dbus/dbus/test/python/test-client.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- test-client.py	7 Nov 2005 12:14:53 -0000	1.13
+++ test-client.py	7 Nov 2005 15:31:30 -0000	1.14
@@ -110,8 +110,8 @@
             
         main_loop.run()
 
-    def testReturnMarshalling(self):
-        print "\n********* Testing return marshalling ***********"
+    def testStrictMarshalling(self):
+        print "\n********* Testing strict return & signal marshalling ***********"
 
         # these values are the same as in the server, and the
         # methods should only succeed when they are called with
@@ -120,33 +120,51 @@
         # with a different number
         values = ["", ("",""), ("","",""), [], {}, ["",""], ["","",""]]
         methods = [
-                    (self.iface.ReturnOneString, set([0]), set([0])),
-                    (self.iface.ReturnTwoStrings, set([1, 5]), set([5])),
-                    (self.iface.ReturnStruct, set([1, 5]), set([1])),
+                    (self.iface.ReturnOneString, 'SignalOneString', set([0]), set([0])),
+                    (self.iface.ReturnTwoStrings, 'SignalTwoStrings', set([1, 5]), set([5])),
+                    (self.iface.ReturnStruct, 'SignalStruct', set([1, 5]), set([1])),
                     # all of our test values are sequences so will marshall correctly into an array :P
-                    (self.iface.ReturnArray, set(range(len(values))), set([3, 5, 6])),
-                    (self.iface.ReturnDict, set([0, 3, 4]), set([4]))
+                    (self.iface.ReturnArray, 'SignalArray', set(range(len(values))), set([3, 5, 6])),
+                    (self.iface.ReturnDict, 'SignalDict', set([0, 3, 4]), set([4]))
                 ]
 
-        for (method, success_values, return_values) in methods:
+        for (method, signal, success_values, return_values) in methods:
             print "\nTrying correct behaviour of", method._method_name
             for value in range(len(values)):
                 try:
                     ret = method(value)
                 except Exception, e:
-                    print "%s(%s) raised %s" % (method._method_name, repr(values[value]), e.__class__)
+                    print "%s(%r) raised %s" % (method._method_name, values[value], e.__class__)
 
                     # should fail if it tried to marshal the wrong type
-                    self.assert_(value not in success_values, "%s should succeed when we ask it to return %s\n%s" % (method._method_name, repr(values[value]), e))
+                    self.assert_(value not in success_values, "%s should succeed when we ask it to return %r\n%s\n%s" % (method._method_name, values[value], e.__class__, e))
                 else:
-                    print "%s(%s) returned %s" % (method._method_name, repr(values[value]), repr(ret))
+                    print "%s(%r) returned %r" % (method._method_name, values[value], ret)
 
                     # should only succeed if it's the right return type
-                    self.assert_(value in success_values, "%s should fail when we ask it to return %s" % (method._method_name, repr(values[value])))
+                    self.assert_(value in success_values, "%s should fail when we ask it to return %r" % (method._method_name, values[value]))
 
                     # check the value is right too :D
                     returns = map(lambda n: values[n], return_values)
-                    self.assert_(ret in returns, "%s should return one of %s" % (method._method_name, repr(returns)))
+                    self.assert_(ret in returns, "%s should return one of %r" % (method._method_name, returns))
+
+            print "\nTrying correct emission of", signal
+            for value in range(len(values)):
+                try:
+                    self.iface.EmitSignal(signal, value)
+                except Exception, e:
+                    print "EmitSignal(%s, %r) raised %s" % (signal, values[value], e.__class__)
+
+                    # should fail if it tried to marshal the wrong type
+                    self.assert_(value not in success_values, "EmitSignal(%s) should succeed when we ask it to return %r\n%s\n%s" % (signal, values[value], e.__class__, e))
+                else:
+                    print "EmitSignal(%s, %r) appeared to succeed" % (signal, values[value])
+
+                    # should only succeed if it's the right return type
+                    self.assert_(value in success_values, "EmitSignal(%s) should fail when we ask it to return %r" % (signal, values[value]))
+
+                    # FIXME: wait for the signal here
+
         print
 
     def testInheritance(self):
@@ -229,6 +247,8 @@
                 else:
                     names[name] = busname
 
+            print
+
 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.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- test-service.py	4 Nov 2005 12:18:00 -0000	1.6
+++ test-service.py	7 Nov 2005 15:31:30 -0000	1.7
@@ -77,6 +77,40 @@
     def ReturnDict(self, test):
         return self.returnValue(test)
 
+    @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='s')
+    def SignalOneString(self, test):
+        pass
+
+    @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='ss')
+    def SignalTwoStrings(self, test, test2):
+        pass
+
+    @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='(ss)')
+    def SignalStruct(self, test):
+        pass
+
+    @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='as')
+    def SignalArray(self, test):
+        pass
+
+    @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='a{ss}')
+    def SignalDict(self, test):
+        pass
+
+    @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='su', out_signature='')
+    def EmitSignal(self, signal, value):
+        sig = getattr(self, signal, None)
+        assert(sig != None)
+
+        val = self.returnValue(value)
+        # make two string case work by passing arguments in by tuple
+        if (signal == 'SignalTwoStrings' and (value == 1 or value == 5)):
+            val = tuple(val)
+        else:
+            val = tuple([val])
+
+        sig(*val)
+
     def CheckInheritance(self):
         return True
 



More information about the dbus-commit mailing list