summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRobert McQueen <robot101@debian.org>2005-10-29 22:41:07 +0000
committerRobert McQueen <robot101@debian.org>2005-10-29 22:41:07 +0000
commita4b1aa364258be053d195650de9062b090f125c6 (patch)
treec41bc919cb375beeea0faa256871e87e093c61d8 /test
parent6fbd1c7ff5b1023f543a304db4f76fc6eeb4dbd5 (diff)
2005-10-29 Robert McQueen <robot101@debian.org>
* python/service.py: Major changes to allow multiple inheritance from classes that define D-Bus interfaces: 1. Create a new Interface class which is the parent class of Object, and make the ObjectType metaclass into InterfaceType. 2. Patch written with Rob Taylor to replace use of method_vtable with code that walks the class's __MRO__ (method resolution order) to behave like Python does when invoking methods and allow overriding as you'd expect. Code is quite tricky because we have to find two methods, the one to invoke which has the right name and isn't decorated with the /wrong/ interface, and the one to pick up the signatures from which is decorated with the right interface. The same caveats apply as to normal multiple inheritance - this has undefined behaviour if you try and inherit from two classes that define a method with the same name but are decorated with different interfaces. You should decorate your overriding method with the interface you want. 3. Replace grungy introspection XML generation code in the metaclass with dictionaries that cope correctly with multiple inheritance and the overriding of methods. This also uses the signature decorations to provide correct introspection data, including the debut appearance of the types of your return values. :D * test/python/test-client.py, test/python/test-service.py: Add a test case to try invoking an method that overrides one inherited from a D-Bus interface class.
Diffstat (limited to 'test')
-rwxr-xr-xtest/python/test-client.py6
-rwxr-xr-xtest/python/test-service.py10
2 files changed, 15 insertions, 1 deletions
diff --git a/test/python/test-client.py b/test/python/test-client.py
index 699bdc45..e84afcdf 100755
--- a/test/python/test-client.py
+++ b/test/python/test-client.py
@@ -144,6 +144,12 @@ class TestDBusBindings(unittest.TestCase):
self.assert_(ret in returns, "%s should return one of %s" % (method._method_name, repr(returns)))
print
+ def testInheritance(self):
+ print "\n********* Testing inheritance from dbus.method.Interface ***********"
+ ret = self.iface.CheckInheritance()
+ print "CheckInheritance returned %s\n", str(ret)
+ self.assert_(ret, "overriding CheckInheritance from TestInterface failed")
+
class TestDBusPythonToGLibBindings(unittest.TestCase):
def setUp(self):
self.bus = dbus.SessionBus()
diff --git a/test/python/test-service.py b/test/python/test-service.py
index 3686480f..ecb9fd60 100755
--- a/test/python/test-service.py
+++ b/test/python/test-service.py
@@ -18,7 +18,12 @@ import dbus.glib
import gobject
import random
-class TestObject(dbus.service.Object):
+class TestInterface(dbus.service.Interface):
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='', out_signature='b')
+ def CheckInheritance(self):
+ return False
+
+class TestObject(dbus.service.Object, TestInterface):
def __init__(self, bus_name, object_path="/org/freedesktop/DBus/TestSuitePythonObject"):
dbus.service.Object.__init__(self, bus_name, object_path)
@@ -72,6 +77,9 @@ class TestObject(dbus.service.Object):
def ReturnDict(self, test):
return self.returnValue(test)
+ def CheckInheritance(self):
+ return True
+
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
object = TestObject(name)