diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-09-16 11:13:22 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-09-23 11:28:31 +0100 |
commit | 4695c8fe269d04eff269522dc6a0f67795a07dac (patch) | |
tree | 9b0e20d89c2c674a978974f29cf5c9d99bbd2f6f /tests | |
parent | a669b92559e7017b6381c44959fc077acc72b11f (diff) |
tests: replace make_mc with class MC
This will make it easier to glue things onto the side of the proxy for
MC.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/account-manager/auto-connect.py | 9 | ||||
-rw-r--r-- | tests/twisted/account-manager/avatar-persist.py | 13 | ||||
-rw-r--r-- | tests/twisted/account-manager/avatar-refresh.py | 13 | ||||
-rw-r--r-- | tests/twisted/account-manager/make-valid.py | 12 | ||||
-rw-r--r-- | tests/twisted/crash-recovery/crash-recovery.py | 18 | ||||
-rw-r--r-- | tests/twisted/dispatcher/create-at-startup.py | 19 | ||||
-rw-r--r-- | tests/twisted/mctest.py | 59 |
7 files changed, 66 insertions, 77 deletions
diff --git a/tests/twisted/account-manager/auto-connect.py b/tests/twisted/account-manager/auto-connect.py index 9f5803a1..38227f5f 100644 --- a/tests/twisted/account-manager/auto-connect.py +++ b/tests/twisted/account-manager/auto-connect.py @@ -27,8 +27,7 @@ import dbus.service from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ call_async, assertEquals -from mctest import exec_test, SimulatedConnection, create_fakecm_account, \ - make_mc +from mctest import exec_test, SimulatedConnection, create_fakecm_account, MC import constants as cs cm_name_ref = dbus.service.BusName( @@ -79,9 +78,9 @@ def test(q, bus, unused): 'password': r'\\ionstorm\\', } - mc = make_mc(bus) + mc = MC(q, bus) - request_conn, prop_changed, _ = q.expect_many( + request_conn, prop_changed = q.expect_many( EventPattern('dbus-method-call', method='RequestConnection', args=['fakeprotocol', expected_params], destination=cs.tp_name_prefix + '.ConnectionManager.fakecm', @@ -90,8 +89,6 @@ def test(q, bus, unused): handled=False), EventPattern('dbus-signal', signal='AccountPropertyChanged', predicate=(lambda e: 'ConnectionStatus' in e.args[0])), - EventPattern('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM and e.args[2]), ) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_', diff --git a/tests/twisted/account-manager/avatar-persist.py b/tests/twisted/account-manager/avatar-persist.py index b4cd6570..06ad65d8 100644 --- a/tests/twisted/account-manager/avatar-persist.py +++ b/tests/twisted/account-manager/avatar-persist.py @@ -28,8 +28,7 @@ import dbus.service from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ call_async -from mctest import exec_test, SimulatedConnection, create_fakecm_account, \ - make_mc +from mctest import exec_test, SimulatedConnection, create_fakecm_account, MC import constants as cs cm_name_ref = dbus.service.BusName( @@ -77,18 +76,14 @@ def test(q, bus, unused): 'password': 'ionstorm', } - mc = make_mc(bus) + mc = MC(q, bus) - e, _ = q.expect_many( - EventPattern('dbus-method-call', method='RequestConnection', + e = q.expect('dbus-method-call', method='RequestConnection', args=['fakeprotocol', expected_params], destination=cs.tp_name_prefix + '.ConnectionManager.fakecm', path=cs.tp_path_prefix + '/ConnectionManager/fakecm', interface=cs.tp_name_prefix + '.ConnectionManager', - handled=False), - EventPattern('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM and e.args[2]), - ) + handled=False) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_', 'myself', has_avatars=True, avatars_persist=True) diff --git a/tests/twisted/account-manager/avatar-refresh.py b/tests/twisted/account-manager/avatar-refresh.py index 87895042..a93912eb 100644 --- a/tests/twisted/account-manager/avatar-refresh.py +++ b/tests/twisted/account-manager/avatar-refresh.py @@ -28,8 +28,7 @@ import dbus.service from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ call_async -from mctest import exec_test, SimulatedConnection, create_fakecm_account, \ - make_mc +from mctest import exec_test, SimulatedConnection, create_fakecm_account, MC import constants as cs cm_name_ref = dbus.service.BusName( @@ -77,18 +76,14 @@ def test(q, bus, unused): 'password': 'ionstorm', } - mc = make_mc(bus) + mc = MC(q, bus) - e, _ = q.expect_many( - EventPattern('dbus-method-call', method='RequestConnection', + e = q.expect('dbus-method-call', method='RequestConnection', args=['fakeprotocol', expected_params], destination=cs.tp_name_prefix + '.ConnectionManager.fakecm', path=cs.tp_path_prefix + '/ConnectionManager/fakecm', interface=cs.tp_name_prefix + '.ConnectionManager', - handled=False), - EventPattern('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM and e.args[2]), - ) + handled=False) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_', 'myself', has_avatars=True, avatars_persist=False) diff --git a/tests/twisted/account-manager/make-valid.py b/tests/twisted/account-manager/make-valid.py index 9853b293..ee3ee98f 100644 --- a/tests/twisted/account-manager/make-valid.py +++ b/tests/twisted/account-manager/make-valid.py @@ -27,8 +27,7 @@ import dbus.service from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ call_async, sync_dbus -from mctest import exec_test, SimulatedConnection, create_fakecm_account, \ - make_mc +from mctest import exec_test, SimulatedConnection, create_fakecm_account, MC import constants as cs cm_name_ref = dbus.service.BusName( @@ -94,14 +93,7 @@ def test(q, bus, unused): q.forbid_events(events) # Wait for MC to load - mc = make_mc(bus) - - q.expect_many( - EventPattern('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM), - EventPattern('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.CD), - ) + mc = MC(q, bus) # Trying to make a channel on account 1 doesn't work, because it's # not valid diff --git a/tests/twisted/crash-recovery/crash-recovery.py b/tests/twisted/crash-recovery/crash-recovery.py index 42963772..e189b850 100644 --- a/tests/twisted/crash-recovery/crash-recovery.py +++ b/tests/twisted/crash-recovery/crash-recovery.py @@ -28,7 +28,7 @@ import dbus.service from servicetest import EventPattern, call_async from mctest import exec_test, SimulatedConnection, SimulatedClient, \ create_fakecm_account, enable_fakecm_account, SimulatedChannel, \ - expect_client_setup, make_mc + expect_client_setup, MC import constants as cs def preseed(): @@ -95,20 +95,8 @@ def test(q, bus, unused): # Service-activate MC. # We're told about the other channel as an observer... - mc = make_mc(bus) - _, _, _, e = q.expect_many( - EventPattern('dbus-signal', - path='/org/freedesktop/DBus', - interface='org.freedesktop.DBus', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM and e.args[2]), - EventPattern('dbus-signal', - path='/org/freedesktop/DBus', - interface='org.freedesktop.DBus', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.CD and e.args[2]), - EventPattern('dbus-signal', - path='/org/freedesktop/DBus', - interface='org.freedesktop.DBus', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.MC and e.args[2]), + mc = MC(q, bus, wait_for_names=False) + e, = mc.wait_for_names( EventPattern('dbus-method-call', path=client.object_path, interface=cs.OBSERVER, method='ObserveChannels', diff --git a/tests/twisted/dispatcher/create-at-startup.py b/tests/twisted/dispatcher/create-at-startup.py index 6cacfc23..c4e24765 100644 --- a/tests/twisted/dispatcher/create-at-startup.py +++ b/tests/twisted/dispatcher/create-at-startup.py @@ -29,7 +29,7 @@ from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ call_async from mctest import exec_test, SimulatedConnection, SimulatedClient, \ create_fakecm_account, enable_fakecm_account, SimulatedChannel, \ - expect_client_setup, make_mc + expect_client_setup, MC import constants as cs def preseed(): @@ -72,9 +72,16 @@ def test(q, bus, unused): cm_name_ref = dbus.service.BusName( cs.tp_name_prefix + '.ConnectionManager.fakecm', bus=bus) - # service-activate MC and immediately make a request - mc = make_mc(bus) + # service-activate MC; it will try to introspect the running client. + mc = MC(q, bus, wait_for_names=False) + get_interfaces, = mc.wait_for_names( + EventPattern('dbus-method-call', path=client.object_path, + interface=cs.PROPERTIES_IFACE, method='Get', + args=[cs.CLIENT, 'Interfaces'], + handled=False)) + # The client doesn't reply just yet; meanwhile, immediately make a channel + # request account = bus.get_object(cs.MC, cs.tp_path_prefix + '/Account/fakecm/fakeprotocol/jc_2edenton_40unatco_2eint') @@ -90,12 +97,6 @@ def test(q, bus, unused): account.object_path, request, user_action_time, client.bus_name, dbus_interface=cs.CD) - get_interfaces = q.expect('dbus-method-call', path=client.object_path, - interface=cs.PROPERTIES_IFACE, method='Get', - args=[cs.CLIENT, 'Interfaces'], - handled=False) - # don't reply just yet - ret = q.expect('dbus-return', method='CreateChannel') request_path = ret.value[0] diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index c9639479..e2a5b54e 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -33,15 +33,6 @@ from twisted.internet import reactor import dbus import dbus.service -def make_mc(bus): - mc = bus.get_object( - cs.tp_name_prefix + '.MissionControl5', - cs.tp_path_prefix + '/MissionControl5', - follow_name_owner_changes=True) - assert mc is not None - - return mc - def install_colourer(): def red(s): return '\x1b[31m%s\x1b[0m' % s @@ -66,16 +57,46 @@ def install_colourer(): sys.stdout = Colourer(sys.stdout, patterns) return sys.stdout -def wait_for_name(queue, bus, name): - if not bus.name_has_owner(name): - queue.expect('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == name and e.args[2]) +class MC(dbus.proxies.ProxyObject): + def __init__(self, queue, bus, wait_for_names=True): + """ + Arguments: + + queue: an event queue + bus: a D-Bus connection + wait_for_names: if True, the constructor will wait for MC to have + been service-activated before returning. if False, + the caller may later call wait_for_names(). + """ + dbus.proxies.ProxyObject.__init__(self, + conn=bus, + bus_name=cs.MC, + object_path=cs.MC_PATH, + follow_name_owner_changes=True) + + self.q = queue + self.bus = bus + + if wait_for_names: + self.wait_for_names() + + def wait_for_names(self, *also_expect): + """ + Waits for MC to have claimed all its bus names, along with the + (optional) EventPatterns passed as arguments. + """ + + patterns = [ + servicetest.EventPattern('dbus-signal', signal='NameOwnerChanged', + predicate=lambda e, name=name: e.args[0] == name and e.args[2] != '') + for name in [cs.AM, cs.CD, cs.MC] + if not self.bus.name_has_owner(name)] + + patterns.extend(also_expect) + + events = self.q.expect_many(*patterns) -def wait_for_mc(queue, bus): - mc = make_mc(bus) - wait_for_name(queue, bus, cs.AM) - wait_for_name(queue, bus, cs.CD) - return mc + return events[3:] def exec_test_deferred (fun, params, protocol=None, timeout=None, preload_mc=True): @@ -95,7 +116,7 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, if preload_mc: try: - mc = wait_for_mc(queue, bus) + mc = MC(queue, bus) except Exception, e: import traceback traceback.print_exc() |