[pygobject] [gi] Add test cases for GDBus client operations
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [gi] Add test cases for GDBus client operations
- Date: Fri, 21 Jan 2011 10:09:28 +0000 (UTC)
commit a060287d1a6d190acb9d344f08fd5662e3296da5
Author: Martin Pitt <martin pitt ubuntu com>
Date: Fri Jan 21 11:00:27 2011 +0100
[gi] Add test cases for GDBus client operations
tests/Makefile.am | 1 +
tests/test_gdbus.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7f71099..dfcb131 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -81,6 +81,7 @@ if ENABLE_INTROSPECTION
TEST_FILES += \
test_everything.py \
test_gi.py \
+ test_gdbus.py \
test_overrides.py
endif
diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py
new file mode 100644
index 0000000..0d5ae94
--- /dev/null
+++ b/tests/test_gdbus.py
@@ -0,0 +1,94 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+
+import unittest
+
+import sys
+sys.path.insert(0, "../")
+
+import gobject
+from gi.repository import GLib
+from gi.repository import Gio
+
+class TestGDBusClient(unittest.TestCase):
+ def setUp(self):
+ self.bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
+
+ self.dbus_proxy = Gio.DBusProxy.new_sync(self.bus,
+ Gio.DBusProxyFlags.NONE, None,
+ 'org.freedesktop.DBus',
+ '/org/freedesktop/DBus',
+ 'org.freedesktop.DBus', None)
+
+ def test_native_calls_sync(self):
+ result = self.dbus_proxy.call_sync('ListNames', None,
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None)
+ self.assert_(isinstance(result, GLib.Variant))
+ result = result.unpack()[0] # result is always a tuple
+ self.assert_(len(result) > 1)
+ self.assert_('org.freedesktop.DBus' in result)
+
+ result = self.dbus_proxy.call_sync('GetNameOwner',
+ GLib.Variant('(s)', 'org.freedesktop.DBus'),
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None)
+ self.assert_(isinstance(result, GLib.Variant))
+ self.assertEqual(type(result.unpack()[0]), type(''))
+
+ def test_native_calls_sync_errors(self):
+ # error case: invalid argument types
+ try:
+ self.dbus_proxy.call_sync('GetConnectionUnixProcessID', None,
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None)
+ self.fail('call with invalid arguments should raise an exception')
+ except Exception, e:
+ self.assert_('InvalidArgs' in e.message)
+
+ # error case: invalid argument
+ try:
+ self.dbus_proxy.call_sync('GetConnectionUnixProcessID',
+ GLib.Variant('(s)', ' unknown'),
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None)
+ self.fail('call with invalid arguments should raise an exception')
+ except Exception, e:
+ self.assert_('NameHasNoOwner' in e.message)
+
+ # error case: unknown method
+ try:
+ self.dbus_proxy.call_sync('UnknownMethod', None,
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None)
+ self.fail('call for unknown method should raise an exception')
+ except Exception, e:
+ self.assert_('UnknownMethod' in e.message)
+
+ def test_native_calls_async(self):
+ def call_done(obj, result, user_data):
+ user_data['result'] = self.dbus_proxy.call_finish(result)
+ user_data['main_loop'].quit()
+
+ main_loop = gobject.MainLoop()
+ data = {'main_loop': main_loop}
+ self.dbus_proxy.call('ListNames', None,
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None,
+ call_done, data)
+ main_loop.run()
+
+ self.assert_(isinstance(data['result'], GLib.Variant))
+ result = data['result'].unpack()[0] # result is always a tuple
+ self.assert_(len(result) > 1)
+ self.assert_('org.freedesktop.DBus' in result)
+
+ def test_native_calls_async_errors(self):
+ def call_done(obj, result, user_data):
+ try:
+ self.dbus_proxy.call_finish(result)
+ self.fail('call_finish() for unknown method should raise an exception')
+ except Exception, e:
+ self.assert_('UnknownMethod' in e.message)
+ finally:
+ user_data['main_loop'].quit()
+
+ main_loop = gobject.MainLoop()
+ data = {'main_loop': main_loop}
+ self.dbus_proxy.call('UnknownMethod', None,
+ Gio.DBusCallFlags.NO_AUTO_START, 500, None, call_done, data)
+ main_loop.run()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]