Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port tests to python 3 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/twisted/cm/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test(q, bus, conn, stream):

protocols = cm_props.Get(cs.CM, 'Protocols')
protocol_names = cm_iface.ListProtocols()
assertEquals(set(protocols.iterkeys()), set(protocol_names))
assertEquals(set(protocols.keys()), set(protocol_names))

for name in protocol_names:
props = protocols[name]
Expand Down
2 changes: 1 addition & 1 deletion tests/twisted/connect/twice-to-same-account.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test(q, bus, conn, stream):
# You might think that this is the test...
try:
cm_iface.RequestConnection('jabber', params)
except dbus.DBusException, e:
except dbus.DBusException as e:
assertEquals(cs.NOT_AVAILABLE, e.get_dbus_name())

# but you'd be wrong: we now test that Haze is still alive.
Expand Down
49 changes: 24 additions & 25 deletions tests/twisted/gabbletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def make_muc_presence(affiliation, role, muc_jid, alias, jid=None, photo=None):
if photo is not None:
presence.addChild(
elem(ns.VCARD_TEMP_UPDATE, 'x')(
elem('photo')(unicode(photo))
elem('photo')(str(photo))
))

return presence
Expand Down Expand Up @@ -129,7 +129,7 @@ def __init__(self, username, password, resource=None, emit_events=False):

def streamStarted(self, root=None):
if root:
self.xmlstream.sid = '%x' % random.randint(1, sys.maxint)
self.xmlstream.sid = '%x' % random.randint(1, sys.maxsize)
self.xmlstream.domain = root.getAttribute('to')

self.xmlstream.sendHeader()
Expand Down Expand Up @@ -165,11 +165,11 @@ def secondIq(self, iq):

def respondToSecondIq(self, iq):
username = xpath.queryForNodes('/iq/query/username', iq)
assert map(str, username) == [self.username]
assert list(map(str, username)) == [self.username]

digest = xpath.queryForNodes('/iq/query/digest', iq)
expect = hashlib.sha1(self.xmlstream.sid + self.password).hexdigest()
assert map(str, digest) == [expect]
assert list(map(str, digest)) == [expect]

resource = xpath.queryForNodes('/iq/query/resource', iq)
assertLength(1, resource)
Expand Down Expand Up @@ -197,7 +197,7 @@ def streamInitialize(self, root):
self.xmlstream.domain = root.getAttribute('to')

if self.xmlstream.sid is None:
self.xmlstream.sid = '%x' % random.randint(1, sys.maxint)
self.xmlstream.sid = '%x' % random.randint(1, sys.maxsize)

self.xmlstream.sendHeader()

Expand Down Expand Up @@ -232,8 +232,8 @@ def streamStarted(self, root=None):
self.streamSASL()

def auth(self, auth):
assert (base64.b64decode(str(auth)) ==
'\x00%s\x00%s' % (self.username, self.password))
assert (base64.b64decode(bytes(auth)) ==
b'\x00%s\x00%s' % (self.username.encode(), self.password.encode()))

success = domish.Element((ns.NS_XMPP_SASL, 'success'))
self.xmlstream.send(success)
Expand Down Expand Up @@ -304,8 +304,7 @@ def __init__(self, streams, jids):
self.streams = streams
self.jids = jids
self.presences = {}
self.mappings = dict(map (lambda jid, stream: (jid, stream),
jids, streams))
self.mappings = dict(zip(jids, streams))

# Make a copy of the streams
self.factory_streams = list(streams)
Expand Down Expand Up @@ -347,7 +346,7 @@ def got_presence (self, stream, jid, stanza):
stream.send(presence)

def lost_presence(self, stream, jid):
if self.presences.has_key(jid):
if jid in self.presences:
del self.presences[jid]
for dest_jid in self.presences.keys():
presence = domish.Element(('jabber:client', 'presence'))
Expand Down Expand Up @@ -556,7 +555,7 @@ def disconnect_conn(q, conn, stream, expected_before=[], expected_after=[]):
return before_events[:-2], after_events[:-1]

def element_repr(element):
"""__repr__ cannot safely return non-ASCII: see
r"""__repr__ cannot safely return non-ASCII: see
<http://bugs.python.org/issue5876>. So we print non-ASCII characters as
\uXXXX escapes in debug output

Expand All @@ -568,7 +567,7 @@ def expect_connected(queue):
args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED])
queue.expect('stream-authenticated')
queue.expect('dbus-signal', signal='PresencesChanged',
args=[{1L: (cs.PRESENCE_AVAILABLE, u'available', '')}])
args=[{1: (cs.PRESENCE_AVAILABLE, u'available', '')}])
queue.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

Expand All @@ -587,7 +586,7 @@ def exec_test_deferred(fun, params, protocol=None, timeout=None,
try:
bus = dbus.SessionBus()
except dbus.exceptions.DBusException as e:
print e
print(e)
os._exit(1)

queue = servicetest.IteratingEventQueue(timeout)
Expand All @@ -607,11 +606,11 @@ def exec_test_deferred(fun, params, protocol=None, timeout=None,

try:
(conn, jid) = make_connection_func(bus, queue.append, params, suffix)
except Exception, e:
except Exception as e:
# Crap. This is normally because the connection's still kicking
# around on the bus. Let's bin any connections we *did* manage to
# get going and then bail out unceremoniously.
print e
print(e)

for conn in conns:
conn.Disconnect()
Expand Down Expand Up @@ -640,7 +639,7 @@ def signal_receiver(*args, **kw):
break
queue.append(Event('dbus-signal',
path=unwrap(kw['path']),
signal=kw['member'], args=map(unwrap, args),
signal=kw['member'], args=list(map(unwrap, args)),
interface=kw['interface']))

match_all_signals = bus.add_signal_receiver(
Expand All @@ -666,7 +665,7 @@ def signal_receiver(*args, **kw):
fun(queue, bus, conns[0], streams[0])
else:
fun(queue, bus, conns, streams)
except Exception, e:
except Exception as e:
traceback.print_exc()
error = e
queue.verbose = False
Expand All @@ -688,19 +687,19 @@ def signal_receiver(*args, **kw):
else:
# Connection is not connected, call Disconnect() to destroy it
conn.Disconnect()
except dbus.DBusException, e:
except dbus.DBusException as e:
pass
except Exception, e:
except Exception as e:
traceback.print_exc()
error = e

try:
conn.Disconnect()
raise AssertionError("Connection didn't disappear; "
"all subsequent tests will probably fail")
except dbus.DBusException, e:
except dbus.DBusException as e:
pass
except Exception, e:
except Exception as e:
traceback.print_exc()
error = e

Expand Down Expand Up @@ -756,7 +755,7 @@ def _elem_add(elem, *children):
for child in children:
if isinstance(child, domish.Element):
elem.addChild(child)
elif isinstance(child, unicode):
elif isinstance(child, str):
elem.addContent(child)
else:
raise ValueError(
Expand Down Expand Up @@ -797,14 +796,14 @@ def __call__(self, *children):

# First, let's pull namespaces out
realattrs = {}
for k, v in allattrs.iteritems():
for k, v in allattrs.items():
if k.startswith('xmlns:'):
abbr = k[len('xmlns:'):]
elem.localPrefixes[abbr] = v
else:
realattrs[k] = v

for k, v in realattrs.iteritems():
for k, v in realattrs.items():
if k == 'from_':
elem['from'] = v
else:
Expand All @@ -820,7 +819,7 @@ def __call__(self, *children):

iq = _iq(server, type)

for k, v in kw.iteritems():
for k, v in kw.items():
if k == 'from_':
iq['from'] = v
else:
Expand Down
28 changes: 14 additions & 14 deletions tests/twisted/roster/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def test(q, bus, conn, stream):
EventPattern('dbus-return', method='AddToGroup'),
)
assertEquals('[email protected]', iq.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)}
assertLength(2, groups)
assertContains(default_group, groups)
assertContains('Scots', groups)
Expand All @@ -121,8 +121,8 @@ def test(q, bus, conn, stream):
EventPattern('dbus-return', method='RemoveFromGroup'),
)
assertEquals('[email protected]', iq.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)}
assertLength(1, groups)
assertContains('Scots', groups)

Expand All @@ -139,8 +139,8 @@ def test(q, bus, conn, stream):
EventPattern('dbus-return', method='SetContactGroups'),
)
assertEquals('[email protected]', iq.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)}
assertLength(2, groups)
assertContains('Scots', groups)
assertContains('Scottish former kings', groups)
Expand All @@ -149,8 +149,8 @@ def test(q, bus, conn, stream):
query_ns=ns.ROSTER),
)
assertEquals('[email protected]', iq.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)}
assertLength(1, groups)
assertContains('Scottish former kings', groups)

Expand All @@ -172,15 +172,15 @@ def test(q, bus, conn, stream):
)

assertEquals('[email protected]', iq1.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq1.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq1.stanza)}
assertLength(2, groups)
assertContains('Still alive', groups)
assertContains(default_group, groups)

assertEquals('[email protected]', iq2.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq2.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq2.stanza)}
assertLength(1, groups)
assertContains(default_group, groups)

Expand All @@ -195,8 +195,8 @@ def test(q, bus, conn, stream):
EventPattern('dbus-return', method='SetGroupMembers'),
)
assertEquals('[email protected]', iq.stanza.query.item['jid'])
groups = set([str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)])
groups = {str(x) for x in xpath.queryForNodes('/iq/query/item/group',
iq.stanza)}
assertLength(1, groups)
assertContains('Capulets', groups)

Expand Down
2 changes: 1 addition & 1 deletion tests/twisted/sasl/telepathy-password.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import constants as cs
from saslutil import connect_and_get_sasl_channel

PASSWORD = "pass"
PASSWORD = b"pass"

def test_close_straight_after_accept(q, bus, conn, stream):
chan, props = connect_and_get_sasl_channel(q, bus, conn)
Expand Down
Loading