aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-02-27 12:56:24 -0500
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-02-27 12:56:24 -0500
commit701aadff88796f71250442156f6e3385648d7b05 (patch)
treef61fac2548d6eda2b66ad27f7e647976e767045c
parent83b5fdc85d50f68722bd1b2cad69e4519ab9b25f (diff)
downloadayatana-indicator-messages-701aadff88796f71250442156f6e3385648d7b05.tar.gz
ayatana-indicator-messages-701aadff88796f71250442156f6e3385648d7b05.tar.bz2
ayatana-indicator-messages-701aadff88796f71250442156f6e3385648d7b05.zip
test-client: wait a bit longer until checking that mock methods were called
-rwxr-xr-xtest/test-client.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/test/test-client.py b/test/test-client.py
index af5d119..a4ac8d2 100755
--- a/test/test-client.py
+++ b/test/test-client.py
@@ -30,39 +30,43 @@ class MessagingMenuTest(dbusmock.DBusTestCase):
self.messaging_service.terminate()
self.messaging_service.wait()
- def spin_loop(self, ms=10):
- GLib.timeout_add(ms, lambda: self.loop.quit())
- self.loop.run()
-
- def assertMethodCalled(self, name, *expected_args):
- calls = self.mock.GetMethodCalls(name)
- self.assertEqual(len(calls), 1, 'method %s was not called' % name)
- args = calls[0][1]
+ def assertArgumentsEqual(self, args, *expected_args):
self.assertEqual(len(args), len(expected_args))
for i in range(len(args)):
if expected_args[i]:
self.assertEqual(args[i], expected_args[i])
+ def assertMethodCalled(self, name, *expected_args):
+ # set a flag on timeout, assertions don't get bubbled up through c functions
+ self.timed_out = False
+ def timeout(): self.timed_out = True
+ timeout_id = GLib.timeout_add_seconds(10, timeout)
+ while 1:
+ calls = self.mock.GetMethodCalls(name)
+ if len(calls) > 0:
+ GLib.source_remove(timeout_id)
+ self.assertArgumentsEqual(calls[0][1], *expected_args)
+ break
+ GLib.MainContext.default().iteration(True)
+ if self.timed_out:
+ raise self.failureException('method %s was not called after 10 seconds' % name)
+
def test_registration(self):
mmapp = MessagingMenu.App.new('test.desktop')
mmapp.register()
- self.spin_loop()
self.assertMethodCalled('RegisterApplication', 'test.desktop', None)
mmapp.unregister()
- self.spin_loop()
self.assertMethodCalled('UnregisterApplication', 'test.desktop')
# ApplicationStoppedRunning is called when the last ref on mmapp is dropped
del mmapp
- self.spin_loop()
self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop')
def test_status(self):
mmapp = MessagingMenu.App.new('test.desktop')
mmapp.register()
mmapp.set_status(MessagingMenu.Status.AWAY)
- self.spin_loop()
self.assertMethodCalled('SetStatus', 'test.desktop', 'away')
unittest.main(testRunner=unittest.TextTestRunner())