diff options
author | Tomi Leppänen <tomi.leppanen@jolla.com> | 2020-08-24 14:47:45 +0300 |
---|---|---|
committer | Tomi Leppänen <tomi.leppanen@jolla.com> | 2020-08-24 14:47:45 +0300 |
commit | 3f0ce4db48ac6389ffacd4ac1a9b24bae989d97c (patch) | |
tree | df67b179dff9f8c76051fa16f6c871f21580c3d1 | |
parent | ada99a651ea8994aa198b2504bdf30c641c7f83a (diff) | |
download | telepathy-mission-control-3f0ce4db48ac6389ffacd4ac1a9b24bae989d97c.tar.gz |
Update tests to Python 3
Run the code through 2to3 tool and fixed parts that need manual fixing.
Also ported dbus-python use to be Python 3 compatible.
Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
24 files changed, 86 insertions, 86 deletions
diff --git a/tests/twisted/account-manager/account-basics.py b/tests/twisted/account-manager/account-basics.py index 18b35cb2..bbad27d6 100644 --- a/tests/twisted/account-manager/account-basics.py +++ b/tests/twisted/account-manager/account-basics.py @@ -256,7 +256,7 @@ def test(q, bus, mc): 'AutomaticPresence', 'ConnectAutomatically', 'RequestedPresence'): try: account_props.Set(cs.ACCOUNT, p, badly_typed) - except dbus.DBusException, e: + except dbus.DBusException as e: assert e.get_dbus_name() == cs.INVALID_ARGUMENT, \ (p, e.get_dbus_name()) else: @@ -265,7 +265,7 @@ def test(q, bus, mc): for p in ('Avatar',): try: account_props.Set(cs.ACCOUNT_IFACE_AVATAR, p, badly_typed) - except dbus.DBusException, e: + except dbus.DBusException as e: assert e.get_dbus_name() == cs.INVALID_ARGUMENT, \ (p, e.get_dbus_name()) else: @@ -275,7 +275,7 @@ def test(q, bus, mc): try: account_props.Set(cs.ACCOUNT_IFACE_NOKIA_CONDITIONS, p, badly_typed) - except dbus.DBusException, e: + except dbus.DBusException as e: assert e.get_dbus_name() == cs.INVALID_ARGUMENT, \ (p, e.get_dbus_name()) else: diff --git a/tests/twisted/account-manager/auto-connect.py b/tests/twisted/account-manager/auto-connect.py index a623902c..fc7dccf0 100644 --- a/tests/twisted/account-manager/auto-connect.py +++ b/tests/twisted/account-manager/auto-connect.py @@ -40,7 +40,7 @@ def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass @@ -155,7 +155,7 @@ def test(q, bus, unused, **kwargs): assert props['ConnectionStatus'] == cs.CONN_STATUS_CONNECTING assert props['ConnectionStatusReason'] == cs.CONN_STATUS_REASON_REQUESTED - print "becoming connected" + print("becoming connected") conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) set_aliases, set_presence, set_avatar, prop_changed = q.expect_many( diff --git a/tests/twisted/account-manager/avatar-refresh.py b/tests/twisted/account-manager/avatar-refresh.py index fe75d3a3..a216191e 100644 --- a/tests/twisted/account-manager/avatar-refresh.py +++ b/tests/twisted/account-manager/avatar-refresh.py @@ -173,7 +173,7 @@ class Account(object): initial_avatar = dbus.Struct((dbus.ByteArray(self.remote_avatar), 'text/plain'), signature='ays') else: - initial_avatar = dbus.Struct((dbus.ByteArray(''), ''), + initial_avatar = dbus.Struct((dbus.ByteArray(b''), ''), signature='ays') conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', @@ -300,7 +300,7 @@ class Account(object): # If we set the avatar to be empty, that's written out as a file, # so it'll override the one in XDG_DATA_DIRS call_async(q, account_props, 'Set', cs.ACCOUNT_IFACE_AVATAR, - 'Avatar', (dbus.ByteArray(''), '')) + 'Avatar', (dbus.ByteArray(b''), '')) q.expect_many( EventPattern('dbus-method-call', @@ -324,7 +324,7 @@ def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass diff --git a/tests/twisted/account-manager/avatar.py b/tests/twisted/account-manager/avatar.py index 353c8992..129c4ef1 100644 --- a/tests/twisted/account-manager/avatar.py +++ b/tests/twisted/account-manager/avatar.py @@ -42,7 +42,7 @@ def test(q, bus, mc): '/telepathy/mission-control/' + avatar_filename) call_async(q, account_props, 'Set', cs.ACCOUNT_IFACE_AVATAR, 'Avatar', - dbus.Struct((dbus.ByteArray('AAAA'), 'image/jpeg'))) + dbus.Struct((dbus.ByteArray(b'AAAA'), 'image/jpeg'))) q.expect_many( EventPattern('dbus-signal', path=account.object_path, @@ -63,7 +63,7 @@ def test(q, bus, mc): method='UpdateAttributes'), ) assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar', - byte_arrays=True) == ('AAAA', 'image/jpeg') + byte_arrays=True) == dbus.Struct((dbus.ByteArray(b'AAAA'), 'image/jpeg')) assertEquals('AAAA', ''.join(open(avatar_filename, 'r').readlines())) # We aren't storing in the old location @@ -75,17 +75,17 @@ def test(q, bus, mc): expect_after_connect=[ EventPattern('dbus-method-call', interface=cs.CONN_IFACE_AVATARS, method='SetAvatar', - handled=True, args=['AAAA', 'image/jpeg']), + handled=True, args=[b'AAAA', 'image/jpeg']), ]) # Change avatar after going online call_async(q, account_props, 'Set', cs.ACCOUNT_IFACE_AVATAR, 'Avatar', - (dbus.ByteArray('BBBB'), 'image/png')) + (dbus.ByteArray(b'BBBB'), 'image/png')) q.expect_many( EventPattern('dbus-method-call', interface=cs.CONN_IFACE_AVATARS, method='SetAvatar', - args=['BBBB', 'image/png'], + args=[b'BBBB', 'image/png'], handled=True), EventPattern('dbus-signal', path=account.object_path, interface=cs.ACCOUNT_IFACE_AVATAR, signal='AvatarChanged'), @@ -104,7 +104,7 @@ def test(q, bus, mc): ) assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar', - byte_arrays=True) == ('BBBB', 'image/png') + byte_arrays=True) == dbus.Struct((dbus.ByteArray(b'BBBB'), 'image/png')) assertEquals('BBBB', ''.join(open(avatar_filename, 'r').readlines())) assert not os.path.exists(os.environ['MC_ACCOUNT_DIR'] + '/fakecm') @@ -117,7 +117,7 @@ def test(q, bus, mc): # Another client changes our avatar remotely q.dbus_emit(conn.object_path, cs.CONN_IFACE_AVATARS, 'AvatarUpdated', - conn.self_handle, 'CCCC', signature='us') + conn.self_handle, b'CCCC', signature='us') e = q.expect('dbus-method-call', interface=cs.CONN_IFACE_AVATARS, method='RequestAvatars', @@ -126,15 +126,15 @@ def test(q, bus, mc): q.dbus_return(e.message, signature='') q.dbus_emit(conn.object_path, cs.CONN_IFACE_AVATARS, - 'AvatarRetrieved', conn.self_handle, 'CCCC', - dbus.ByteArray('CCCC'), 'image/svg', signature='usays') + 'AvatarRetrieved', conn.self_handle, b'CCCC', + dbus.ByteArray(b'CCCC'), 'image/svg', signature='usays') q.expect_many( EventPattern('dbus-signal', path=account.object_path, interface=cs.ACCOUNT_IFACE_AVATAR, signal='AvatarChanged'), EventPattern('dbus-signal', interface=cs.TEST_DBUS_ACCOUNT_PLUGIN_IFACE, signal='DeferringSetAttribute', - args=[account.object_path, 'avatar_token', 'CCCC']), + args=[account.object_path, 'avatar_token', b'CCCC']), EventPattern('dbus-signal', interface=cs.TEST_DBUS_ACCOUNT_PLUGIN_IFACE, signal='CommittingOne', @@ -145,7 +145,7 @@ def test(q, bus, mc): ) assert account_props.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar', - byte_arrays=True) == ('CCCC', 'image/svg') + byte_arrays=True) == dbus.Struct((dbus.ByteArray(b'CCCC'), 'image/svg')) assertEquals('CCCC', ''.join(open(avatar_filename, 'r').readlines())) diff --git a/tests/twisted/account-manager/create-with-properties.py b/tests/twisted/account-manager/create-with-properties.py index 6e208806..85733d2f 100644 --- a/tests/twisted/account-manager/create-with-properties.py +++ b/tests/twisted/account-manager/create-with-properties.py @@ -68,7 +68,7 @@ def test(q, bus, mc): cs.ACCOUNT + '.Icon': 'quake3arena', cs.ACCOUNT + '.Nickname': 'AnArKi', cs.ACCOUNT + '.ConnectAutomatically': True, - cs.ACCOUNT_IFACE_AVATAR + '.Avatar': (dbus.ByteArray('foo'), + cs.ACCOUNT_IFACE_AVATAR + '.Avatar': (dbus.ByteArray(b'foo'), 'image/jpeg'), cs.ACCOUNT_IFACE_NOKIA_CONDITIONS + '.Condition': dbus.Dictionary({ 'has-quad-damage': ':y' }, signature='ss'), diff --git a/tests/twisted/account-manager/make-valid.py b/tests/twisted/account-manager/make-valid.py index 7c1df852..19813a8c 100644 --- a/tests/twisted/account-manager/make-valid.py +++ b/tests/twisted/account-manager/make-valid.py @@ -41,7 +41,7 @@ def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass diff --git a/tests/twisted/account-manager/param-types.py b/tests/twisted/account-manager/param-types.py index 8dafd7f1..319c052d 100644 --- a/tests/twisted/account-manager/param-types.py +++ b/tests/twisted/account-manager/param-types.py @@ -39,11 +39,11 @@ def test(q, bus, mc): 'o': dbus.ObjectPath('/lalala'), 'b': False, 'q': dbus.UInt16(42), - 'u': dbus.UInt32(0xFFFFFFFFL), - 't': dbus.UInt64(0xFFFFffffFFFFffffL), + 'u': dbus.UInt32(0xFFFFFFFF), + 't': dbus.UInt64(0xFFFFffffFFFFffff), 'n': dbus.Int16(-42), 'i': dbus.Int32(-42), - 'x': dbus.Int64(-1 * 0x7FFFffffFFFFffffL), + 'x': dbus.Int64(-1 * 0x7FFFffffFFFFffff), 'd': 4.5, 'y': dbus.Byte(42), 'as': dbus.Array(['one', 'two', 'three'], signature='s') diff --git a/tests/twisted/account-manager/reconnect.py b/tests/twisted/account-manager/reconnect.py index 44af4100..f46628df 100644 --- a/tests/twisted/account-manager/reconnect.py +++ b/tests/twisted/account-manager/reconnect.py @@ -52,7 +52,7 @@ def test(q, bus, mc): q.expect('dbus-return', method='Set') requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE), - dbus.String(u'available'), dbus.String(u''))) + dbus.String('available'), dbus.String(''))) call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) @@ -66,7 +66,7 @@ def test(q, bus, mc): # While we want to be offline but the account is enabled, Reconnect is # still a no-op. requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), - dbus.String(u'offline'), dbus.String(u''))) + dbus.String('offline'), dbus.String(''))) call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) @@ -99,7 +99,7 @@ def test(q, bus, mc): q.unforbid_events(looks_like_reconnection) requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE), - dbus.String(u'brb'), dbus.String(u'Be back soon!'))) + dbus.String('brb'), dbus.String('Be back soon!'))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/account-manager/request-online.py b/tests/twisted/account-manager/request-online.py index 3d8a6016..05c01554 100644 --- a/tests/twisted/account-manager/request-online.py +++ b/tests/twisted/account-manager/request-online.py @@ -34,7 +34,7 @@ def test(q, bus, mc): tp_name_prefix + '.ConnectionManager.fakecm', bus=bus) http_fixed_properties = dbus.Dictionary({ - cs.CHANNEL + '.TargetHandleType': 1L, + cs.CHANNEL + '.TargetHandleType': 1, cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAM_TUBE, cs.CHANNEL_TYPE_STREAM_TUBE + '.Service': 'http' @@ -76,8 +76,8 @@ def test(q, bus, mc): assertEquals(cs.PRESENCE_TYPE_OFFLINE, props['CurrentPresence'][0]) # Go online - requested_presence = dbus.Struct((dbus.UInt32(2L), dbus.String(u'brb'), - dbus.String(u'Be back soon!'))) + requested_presence = dbus.Struct((dbus.UInt32(2), dbus.String('brb'), + dbus.String('Be back soon!'))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/account-manager/update-parameters.py b/tests/twisted/account-manager/update-parameters.py index a7ec6a0a..637b4905 100644 --- a/tests/twisted/account-manager/update-parameters.py +++ b/tests/twisted/account-manager/update-parameters.py @@ -50,8 +50,8 @@ def test(q, bus, mc, **kwargs): interface=cs.ACCOUNT) # Go online - requested_presence = dbus.Struct((dbus.UInt32(2L), dbus.String(u'brb'), - dbus.String(u'Be back soon!'))) + requested_presence = dbus.Struct((dbus.UInt32(2), dbus.String('brb'), + dbus.String('Be back soon!'))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/account-storage/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py index 2d3b2fcf..4ffda0e0 100644 --- a/tests/twisted/account-storage/default-keyring-storage.py +++ b/tests/twisted/account-storage/default-keyring-storage.py @@ -149,7 +149,7 @@ def test(q, bus, mc): low_prio_key_file_name = os.path.join( os.environ['XDG_DATA_DIRS'].split(':')[0], 'telepathy', 'mission-control', 'accounts.cfg') - os.makedirs(os.path.dirname(low_prio_key_file_name), 0700) + os.makedirs(os.path.dirname(low_prio_key_file_name), 0o700) # This is deliberately a lower-priority location os.remove(new_key_file_name) @@ -224,7 +224,7 @@ AutomaticPresence=2;available;; if __name__ == '__main__': ctl_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(ctl_dir, 0700) + os.mkdir(ctl_dir, 0o700) except OSError: pass exec_test(test, {}, timeout=10, use_fake_accounts_service=False) diff --git a/tests/twisted/account-storage/diverted-storage.py b/tests/twisted/account-storage/diverted-storage.py index 8692b09b..95df528e 100644 --- a/tests/twisted/account-storage/diverted-storage.py +++ b/tests/twisted/account-storage/diverted-storage.py @@ -35,7 +35,7 @@ import constants as cs def test(q, bus, mc): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass diff --git a/tests/twisted/account-storage/libaccounts-sso-storage.py b/tests/twisted/account-storage/libaccounts-sso-storage.py index a2e7b512..bd1887ad 100644 --- a/tests/twisted/account-storage/libaccounts-sso-storage.py +++ b/tests/twisted/account-storage/libaccounts-sso-storage.py @@ -34,7 +34,7 @@ from mctest import exec_test, create_fakecm_account, get_account_manager, \ import constants as cs if ('ACCOUNTS' not in os.environ or not os.environ['ACCOUNTS']): - print "Not testing accounts-sso storage" + print("Not testing accounts-sso storage") sys.exit(0) def account_store(op, backend, key=None, value=None): @@ -73,7 +73,7 @@ def test(q, bus, mc): assert len(ia) == 1 account_path = ia[0] - print repr(account_path) + print(repr(account_path)) account = get_fakecm_account(bus, mc, account_path) account_iface = dbus.Interface(account, cs.ACCOUNT) diff --git a/tests/twisted/capabilities/contact-caps.py b/tests/twisted/capabilities/contact-caps.py index 7a348df0..0004dce6 100644 --- a/tests/twisted/capabilities/contact-caps.py +++ b/tests/twisted/capabilities/contact-caps.py @@ -78,8 +78,8 @@ def test(q, bus, mc): for struct in structs: assert struct[0] not in filters - filters[struct[0]] = sorted(struct[1]) - tokens[struct[0]] = sorted(struct[2]) + filters[struct[0]] = struct[1] + tokens[struct[0]] = struct[2] assert media_fixed_properties in filters[cs.CLIENT + '.MediaCall'] assert len(filters[cs.CLIENT + '.MediaCall']) == 1 diff --git a/tests/twisted/crash-recovery/crash-recovery.py b/tests/twisted/crash-recovery/crash-recovery.py index 2bc45349..92991700 100644 --- a/tests/twisted/crash-recovery/crash-recovery.py +++ b/tests/twisted/crash-recovery/crash-recovery.py @@ -37,7 +37,7 @@ def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass diff --git a/tests/twisted/dispatcher/already-has-channel.py b/tests/twisted/dispatcher/already-has-channel.py index 547acdf2..dd780f51 100644 --- a/tests/twisted/dispatcher/already-has-channel.py +++ b/tests/twisted/dispatcher/already-has-channel.py @@ -55,8 +55,8 @@ def test(q, bus, mc): account.Set(cs.ACCOUNT, 'Enabled', True, dbus_interface=cs.PROPERTIES_IFACE) - requested_presence = dbus.Struct((dbus.UInt32(2L), - dbus.String(u'available'), dbus.String(u''))) + requested_presence = dbus.Struct((dbus.UInt32(2), + dbus.String('available'), dbus.String(''))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/dispatcher/already-has-obsolete.py b/tests/twisted/dispatcher/already-has-obsolete.py index 05dcb115..f7db760f 100644 --- a/tests/twisted/dispatcher/already-has-obsolete.py +++ b/tests/twisted/dispatcher/already-has-obsolete.py @@ -55,8 +55,8 @@ def test(q, bus, mc): account.Set(cs.ACCOUNT, 'Enabled', True, dbus_interface=cs.PROPERTIES_IFACE) - requested_presence = dbus.Struct((dbus.UInt32(2L), - dbus.String(u'available'), dbus.String(u''))) + requested_presence = dbus.Struct((dbus.UInt32(2), + dbus.String('available'), dbus.String(''))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/dispatcher/cancel.py b/tests/twisted/dispatcher/cancel.py index 5b8d90af..b3b0ea0a 100644 --- a/tests/twisted/dispatcher/cancel.py +++ b/tests/twisted/dispatcher/cancel.py @@ -95,7 +95,7 @@ def test_channel_creation(q, bus, account, client, conn, # the channel request has gone away try: cr.Proceed(dbus_interface=cs.CR) - except dbus.DBusException, e: + except dbus.DBusException as e: pass else: raise AssertionError('Wanted an error') diff --git a/tests/twisted/dispatcher/create-at-startup.py b/tests/twisted/dispatcher/create-at-startup.py index e0d73722..a6c10c77 100644 --- a/tests/twisted/dispatcher/create-at-startup.py +++ b/tests/twisted/dispatcher/create-at-startup.py @@ -38,7 +38,7 @@ def preseed(q, bus, fake_accounts_service): accounts_dir = os.environ['MC_ACCOUNT_DIR'] try: - os.mkdir(accounts_dir, 0700) + os.mkdir(accounts_dir, 0o700) except OSError: pass diff --git a/tests/twisted/fakeaccountsservice.py b/tests/twisted/fakeaccountsservice.py index 3c10a156..5819af26 100644 --- a/tests/twisted/fakeaccountsservice.py +++ b/tests/twisted/fakeaccountsservice.py @@ -118,7 +118,7 @@ class FakeAccountsService(object): if account not in self.accounts: self.create_account(account) - for (attribute, value) in changed.items(): + for (attribute, value) in list(changed.items()): self.accounts[account][ATTRS][attribute] = value self.accounts[account][ATTR_FLAGS][attribute] = flags.get( attribute, dbus.UInt32(0)) @@ -149,14 +149,14 @@ class FakeAccountsService(object): if account not in self.accounts: self.create_account(account) - for (param, value) in changed.items(): + for (param, value) in list(changed.items()): self.accounts[account][PARAMS][param] = value if param in self.accounts[account][UNTYPED_PARAMS]: del self.accounts[account][UNTYPED_PARAMS][param] self.accounts[account][PARAM_FLAGS][param] = flags.get( param, dbus.UInt32(0)) - for (param, value) in untyped.items(): + for (param, value) in list(untyped.items()): self.accounts[account][UNTYPED_PARAMS][param] = value if param in self.accounts[account][PARAMS]: del self.accounts[account][PARAMS][param] diff --git a/tests/twisted/fakeclient.py b/tests/twisted/fakeclient.py index d3c43813..0b08c606 100644 --- a/tests/twisted/fakeclient.py +++ b/tests/twisted/fakeclient.py @@ -63,8 +63,8 @@ class FakeClient(dbus.service.Object): if interface_name == client_handler_iface and \ property_name == "HandlerChannelFilter": return self.caps - print "Error: interface_name=%s property_name=%s" % \ - (interface_name, property_name) + print("Error: interface_name=%s property_name=%s" % \ + (interface_name, property_name)) return None @dbus.service.method(dbus_interface=properties_iface, diff --git a/tests/twisted/fakecm.py b/tests/twisted/fakecm.py index fb534e7b..51621d91 100644 --- a/tests/twisted/fakecm.py +++ b/tests/twisted/fakecm.py @@ -104,7 +104,7 @@ class FakeConn(dbus.service.Object): return dbus.Array([conn_iface, caps_iface, requests_iface]) def get_handle(self, id): - for handle, id_ in self.handles.iteritems(): + for handle, id_ in self.handles.items(): if id_ == id: return handle handle = self.next_handle @@ -134,12 +134,12 @@ class FakeConn(dbus.service.Object): obj=self, path=self.object_path, handle_type=handle_type, handles=handles)) if handle_type != 1: - raise "non-contact handles don't exist" + raise Exception("non-contact handles don't exist") ret = [] for handle in handles: if handle not in self.handles: - raise "%d is not a valid handle" % handle + raise Exception("%d is not a valid handle" % handle) ret.append(self.handles[handle]) return ret @@ -148,7 +148,7 @@ class FakeConn(dbus.service.Object): in_signature='uas', out_signature='au') def RequestHandles(self, type, ids): if type != 1: - raise "non-contact handles don't exist" + raise Exception("non-contact handles don't exist") ret = [] for id in ids: @@ -190,8 +190,8 @@ class FakeConn(dbus.service.Object): if interface_name == requests_iface and \ property_name == "Channels": return dbus.Array(self.channels, signature='(oa{sv})') - print "Error: interface_name=%s property_name=%s" % \ - (interface_name, property_name) + print("Error: interface_name=%s property_name=%s" % \ + (interface_name, property_name)) return None @dbus.service.method(dbus_interface=properties_iface, @@ -201,7 +201,7 @@ class FakeConn(dbus.service.Object): obj=self, interface_name=interface_name)) if interface_name == conn_iface: return dbus.Dictionary({ - 'SelfHandle': 0L + 'SelfHandle': 0 }, signature='sv') if interface_name == requests_iface: return dbus.Dictionary({ diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index 2909acc9..9460188c 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -124,7 +124,7 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, if preload_mc: try: mc = MC(queue, bus, initially_online=initially_online) - except Exception, e: + except Exception as e: import traceback traceback.print_exc() os._exit(1) @@ -149,7 +149,7 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, try: fun(queue, bus, mc, **kwargs) - except Exception, e: + except Exception as e: import traceback traceback.print_exc() error = e @@ -168,25 +168,25 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) - except dbus.DBusException, e: - print >> sys.stderr, "Can't set %s offline: %s" % (a, e) + except dbus.DBusException as e: + print("Can't set %s offline: %s" % (a, e), file=sys.stderr) try: account.Properties.Set(cs.ACCOUNT, 'Enabled', False) - except dbus.DBusException, e: - print >> sys.stderr, "Can't disable %s: %s" % (a, e) + except dbus.DBusException as e: + print("Can't disable %s: %s" % (a, e), file=sys.stderr) try: account.Remove() - except dbus.DBusException, e: - print >> sys.stderr, "Can't remove %s: %s" % (a, e) + except dbus.DBusException as e: + print("Can't remove %s: %s" % (a, e), file=sys.stderr) servicetest.sync_dbus(bus, queue, am) - except dbus.DBusException, e: - print >> sys.stderr, "Couldn't clean up left-over accounts: %s" % e + except dbus.DBusException as e: + print("Couldn't clean up left-over accounts: %s" % e, file=sys.stderr) - except Exception, e: + except Exception as e: import traceback traceback.print_exc() error = e @@ -272,7 +272,7 @@ class SimulatedConnection(object): if initial_avatar is not None: self.avatar = initial_avatar elif self.avatars_persist: - self.avatar = dbus.Struct((dbus.ByteArray('my old avatar'), + self.avatar = dbus.Struct((dbus.ByteArray(b'my old avatar'), 'text/plain'), signature='ays') else: self.avatar = None @@ -415,7 +415,7 @@ class SimulatedConnection(object): }, signature='a{sv}') def forget_avatar(self): - self.avatar = (dbus.ByteArray(''), '') + self.avatar = (dbus.ByteArray(b''), '') self.avatar_delayed = False # not actually very relevant for MC so hard-code 0 for now @@ -1052,9 +1052,9 @@ def create_fakecm_account(q, bus, mc, params, properties={}, account = Account(bus, account_path) - for key, value in properties.iteritems(): + for key, value in properties.items(): interface, prop = key.rsplit('.', 1) - servicetest.assertEquals(value, account.Properties.Get(interface, prop)) + servicetest.assertEqual(value, account.Properties.Get(interface, prop)) return (cm_name_ref, account) diff --git a/tests/twisted/servicetest.py b/tests/twisted/servicetest.py index 4dc604f3..1f1c1645 100644 --- a/tests/twisted/servicetest.py +++ b/tests/twisted/servicetest.py @@ -20,9 +20,9 @@ Infrastructure code for testing Mission Control """ -from twisted.internet import glib2reactor +from twisted.internet import gireactor from twisted.internet.protocol import Protocol, Factory, ClientFactory -glib2reactor.install() +gireactor.install() import sys import pprint @@ -80,7 +80,7 @@ class EventPattern: if event.type != self.type: return False - for key, value in self.properties.iteritems(): + for key, value in self.properties.items(): try: if getattr(event, key) != value: return False @@ -122,14 +122,14 @@ class BaseEventQueue: def log(self, s): if self.verbose: - print s + print(s) def log_event(self, event): if self.verbose: self.log('got event:') if self.verbose: - map(self.log, format_event(event)) + list(map(self.log, format_event(event))) def flush_past_events(self): self.past_events = [] @@ -140,7 +140,7 @@ class BaseEventQueue: for event in self.past_events: if pattern.match(event): self.log('past event handled') - map(self.log, format_event(event)) + list(map(self.log, format_event(event))) self.log('') self.past_events.remove(event) return event @@ -331,7 +331,7 @@ class IteratingEventQueue(BaseEventQueue): Event('dbus-signal', path=unwrap(kw['path']), signal=kw['member'], - args=map(unwrap, args), + args=list(map(unwrap, args)), interface=kw['interface'])), None, None, @@ -365,7 +365,7 @@ class IteratingEventQueue(BaseEventQueue): e = Event('dbus-method-call', message=message, interface=message.get_interface(), path=message.get_path(), raw_args=message.get_args_list(byte_arrays=True), - args=map(unwrap, message.get_args_list(byte_arrays=True)), + args=list(map(unwrap, message.get_args_list(byte_arrays=True))), destination=str(destination), method=message.get_member(), sender=message.get_sender(), @@ -437,18 +437,18 @@ def unwrap(x): printed.""" if isinstance(x, list): - return map(unwrap, x) + return list(map(unwrap, x)) if isinstance(x, tuple): return tuple(map(unwrap, x)) if isinstance(x, dict): - return dict([(unwrap(k), unwrap(v)) for k, v in x.iteritems()]) + return dict([(unwrap(k), unwrap(v)) for k, v in x.items()]) if isinstance(x, dbus.Boolean): return bool(x) - for t in [unicode, str, long, int, float]: + for t in [str, str, int, int, float]: if isinstance(x, t): return t(x) @@ -489,7 +489,7 @@ class ProxyWrapper: dbus.Interface(object, tp_name_prefix + '.Properties') self.interfaces = dict([ (name, dbus.Interface(object, iface)) - for name, iface in others.iteritems()]) + for name, iface in others.items()]) def __getattr__(self, name): if name in self.interfaces: @@ -575,7 +575,7 @@ def watch_tube_signals(q, tube): q.handle_event(Event('tube-signal', path=kwargs['path'], signal=kwargs['member'], - args=map(unwrap, args), + args=list(map(unwrap, args)), tube=tube)) tube.add_signal_receiver(got_signal_cb, |