[telepathy-gabble/master] clean up pyflakes warnings in tests

Dafydd Harries daf at rhydd.org
Wed Apr 8 04:09:13 PDT 2009


---
 tests/twisted/bytestream.py                        |    3 +-
 tests/twisted/connect/test-nonblocking-tls.py      |    8 +-
 tests/twisted/connect/test-twice.py                |   10 +--
 .../twisted/file-transfer/file_transfer_helper.py  |   16 ++--
 ...eceive-file-and-close-socket-while-receiving.py |    1 -
 .../test-receive-file-and-disconnect.py            |    1 -
 tests/twisted/gabbletest.py                        |    1 -
 tests/twisted/jingle/call-state.py                 |    6 +-
 tests/twisted/jingle/google-relay.py               |    1 -
 tests/twisted/jingle/hold-audio.py                 |    1 -
 tests/twisted/jingle/hold-av.py                    |    8 +--
 tests/twisted/jingle/jingletest2.py                |   12 ++--
 tests/twisted/jingle/outgoing-many-streams.py      |   13 ++--
 tests/twisted/jingle/payload-types.py              |   13 +--
 tests/twisted/jingle/stream-handler-error.py       |    2 +-
 tests/twisted/jingle/stun-server.py                |   27 +++---
 .../twisted/jingle/test-content-adding-removal.py  |   35 +++----
 tests/twisted/jingle/test-content-complex.py       |   11 +--
 tests/twisted/jingle/test-description-info.py      |   15 ++--
 tests/twisted/jingle/test-dialects-incoming.py     |   12 +--
 tests/twisted/jingle/test-dialects-outgoing.py     |    9 +--
 tests/twisted/jingle/test-incoming-call.py         |   12 +--
 .../jingle/test-outgoing-call-deprecated.py        |    5 +-
 .../jingle/test-outgoing-call-deprecated2.py       |    9 +-
 tests/twisted/jingle/test-outgoing-call-ensure.py  |   13 +--
 .../twisted/jingle/test-outgoing-call-rejected.py  |    3 +-
 .../jingle/test-outgoing-call-requestotron.py      |   12 +--
 tests/twisted/jingle/test-outgoing-call.py         |   13 +--
 tests/twisted/presence/presence.py                 |    4 +-
 tests/twisted/roster/ensure.py                     |   18 ++---
 tests/twisted/roster/request-group-after-roster.py |   13 +--
 .../twisted/roster/request-group-before-roster.py  |    2 -
 tests/twisted/roster/test-google-roster.py         |    5 +-
 tests/twisted/roster/test-roster-item-deletion.py  |    2 +-
 tests/twisted/test-capabilities.py                 |    2 -
 tests/twisted/test-caps-cache.py                   |    5 +-
 tests/twisted/test-caps-hash.py                    |    3 +-
 tests/twisted/test-disco-no-reply.py               |    2 -
 tests/twisted/test-location.py                     |    2 +-
 tests/twisted/text/ensure.py                       |    2 -
 tests/twisted/text/initiate-requestotron.py        |    2 -
 tests/twisted/text/send-error.py                   |    2 -
 tests/twisted/text/test-chat-state.py              |    2 -
 tests/twisted/text/test-text-delayed.py            |    4 +-
 tests/twisted/tubes/accept-muc-dbus-tube.py        |    2 +-
 tests/twisted/tubes/accept-muc-stream-tube.py      |    2 +-
 tests/twisted/tubes/close-muc-with-closed-tube.py  |   13 +--
 tests/twisted/tubes/crash-on-list-channels.py      |    6 +-
 .../twisted/tubes/create-invalid-tube-channels.py  |   23 +++---
 tests/twisted/tubes/ensure-si-tube.py              |   13 +---
 tests/twisted/tubes/muctubeutil.py                 |    4 +-
 tests/twisted/tubes/offer-muc-dbus-tube.py         |   92 ++++++++++----------
 tests/twisted/tubes/offer-muc-stream-tube.py       |    2 +-
 tests/twisted/tubes/offer-private-stream-tube.py   |    2 +-
 tests/twisted/tubes/request-invalid-dbus-tube.py   |   12 ++--
 tests/twisted/tubes/test-get-available-tubes.py    |    6 +-
 tests/twisted/tubes/tubetestutil.py                |   96 +++++++++++---------
 tests/twisted/vcard/test-avatar-retrieved.py       |    1 -
 tests/twisted/vcard/test-save-alias-to-vcard.py    |    6 +-
 tests/twisted/vcard/test-vcard-race.py             |    8 +-
 60 files changed, 262 insertions(+), 368 deletions(-)

diff --git a/tests/twisted/bytestream.py b/tests/twisted/bytestream.py
index f1772fb..f42d1ed 100644
--- a/tests/twisted/bytestream.py
+++ b/tests/twisted/bytestream.py
@@ -11,8 +11,7 @@ from twisted.words.xish import xpath, domish
 from twisted.internet.error import CannotListenError
 
 from servicetest import Event, EventPattern
-from gabbletest import acknowledge_iq, sync_stream, make_result_iq, elem_iq,\
-    elem
+from gabbletest import acknowledge_iq, make_result_iq, elem_iq, elem
 import ns
 
 def wait_events(q, expected, my_event):
diff --git a/tests/twisted/connect/test-nonblocking-tls.py b/tests/twisted/connect/test-nonblocking-tls.py
index c130223..776fef6 100644
--- a/tests/twisted/connect/test-nonblocking-tls.py
+++ b/tests/twisted/connect/test-nonblocking-tls.py
@@ -9,13 +9,11 @@ import sys
 import dbus
 import servicetest
 
-import twisted
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import domish
 from twisted.words.protocols.jabber import xmlstream
 
-from gabbletest import make_connection, make_stream, JabberAuthenticator, \
-                       XmppAuthenticator, \
-                       XmppXmlStream, JabberXmlStream
+from gabbletest import (
+    make_connection, make_stream, XmppAuthenticator, XmppXmlStream)
 
 NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls'
 NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
diff --git a/tests/twisted/connect/test-twice.py b/tests/twisted/connect/test-twice.py
index 731f8c1..4336494 100644
--- a/tests/twisted/connect/test-twice.py
+++ b/tests/twisted/connect/test-twice.py
@@ -9,13 +9,9 @@ import sys
 import dbus
 import servicetest
 
-import twisted
-from twisted.words.xish import domish, xpath
-from twisted.words.protocols.jabber import xmlstream
-
-from gabbletest import make_connection, make_stream, JabberAuthenticator, \
-                       XmppAuthenticator, \
-                       XmppXmlStream, JabberXmlStream
+from gabbletest import (
+    make_connection, make_stream, JabberAuthenticator, XmppAuthenticator,
+    XmppXmlStream, JabberXmlStream)
 
 def test(q, bus, conn1, conn2, stream1, stream2):
     # Connection 1
diff --git a/tests/twisted/file-transfer/file_transfer_helper.py b/tests/twisted/file-transfer/file_transfer_helper.py
index 52876a0..1d969a1 100644
--- a/tests/twisted/file-transfer/file_transfer_helper.py
+++ b/tests/twisted/file-transfer/file_transfer_helper.py
@@ -7,9 +7,8 @@ import datetime
 from servicetest import EventPattern
 from gabbletest import exec_test, sync_stream
 import ns
-from bytestream import create_from_si_offer, BytestreamIBBMsg, BytestreamS5B, BytestreamS5BPidgin, \
-    BytestreamSIFallbackS5CannotConnect, BytestreamSIFallbackS5WrongHash, BytestreamS5BRelay,\
-    BytestreamS5BRelayBugged, announce_socks5_proxy
+from bytestream import create_from_si_offer, announce_socks5_proxy
+import bytestream
 
 from twisted.words.xish import domish, xpath
 
@@ -418,9 +417,14 @@ class SendFileTest(FileTransferTest):
         assert reason == cs.FT_STATE_CHANGE_REASON_NONE
 
 def exec_file_transfer_test(test_cls):
-    for bytestream_cls  in [BytestreamIBBMsg, BytestreamS5B, BytestreamS5BPidgin,\
-        BytestreamSIFallbackS5CannotConnect, BytestreamSIFallbackS5WrongHash,\
-        BytestreamS5BRelay, BytestreamS5BRelayBugged]:
+    for bytestream_cls  in [
+            bytestream.BytestreamIBBMsg,
+            bytestream.BytestreamS5B,
+            bytestream.BytestreamS5BPidgin,
+            bytestream.BytestreamSIFallbackS5CannotConnect,
+            bytestream.BytestreamSIFallbackS5WrongHash,
+            bytestream.BytestreamS5BRelay,
+            bytestream.BytestreamS5BRelayBugged]:
         for addr_type, access_control, access_control_param in [
                 (cs.SOCKET_ADDRESS_TYPE_UNIX, cs.SOCKET_ACCESS_CONTROL_LOCALHOST, ""),
                 (cs.SOCKET_ADDRESS_TYPE_IPV4, cs.SOCKET_ACCESS_CONTROL_LOCALHOST, ""),
diff --git a/tests/twisted/file-transfer/test-receive-file-and-close-socket-while-receiving.py b/tests/twisted/file-transfer/test-receive-file-and-close-socket-while-receiving.py
index 373243d..9d04cf3 100644
--- a/tests/twisted/file-transfer/test-receive-file-and-close-socket-while-receiving.py
+++ b/tests/twisted/file-transfer/test-receive-file-and-close-socket-while-receiving.py
@@ -1,4 +1,3 @@
-import socket
 
 import constants as cs
 from file_transfer_helper import exec_file_transfer_test, ReceiveFileTest
diff --git a/tests/twisted/file-transfer/test-receive-file-and-disconnect.py b/tests/twisted/file-transfer/test-receive-file-and-disconnect.py
index 5ae0ff7..3ff24ad 100644
--- a/tests/twisted/file-transfer/test-receive-file-and-disconnect.py
+++ b/tests/twisted/file-transfer/test-receive-file-and-disconnect.py
@@ -1,4 +1,3 @@
-import socket
 
 from file_transfer_helper import exec_file_transfer_test, ReceiveFileTest
 
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index 721302a..c76bbf1 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -7,7 +7,6 @@ import base64
 import os
 import sha
 import sys
-import time
 import random
 
 import ns
diff --git a/tests/twisted/jingle/call-state.py b/tests/twisted/jingle/call-state.py
index 5e0690e..9664a09 100644
--- a/tests/twisted/jingle/call-state.py
+++ b/tests/twisted/jingle/call-state.py
@@ -5,9 +5,9 @@ interface.
 
 from twisted.words.xish import xpath
 
-from gabbletest import make_result_iq, sync_stream
-from servicetest import wrap_channel, make_channel_proxy, call_async, \
-    EventPattern, tp_path_prefix
+from gabbletest import make_result_iq
+from servicetest import (
+    wrap_channel, make_channel_proxy, EventPattern, tp_path_prefix)
 import ns
 import constants as cs
 
diff --git a/tests/twisted/jingle/google-relay.py b/tests/twisted/jingle/google-relay.py
index 74dfeca..a1400c5 100644
--- a/tests/twisted/jingle/google-relay.py
+++ b/tests/twisted/jingle/google-relay.py
@@ -10,7 +10,6 @@ import jingletest
 import gabbletest
 import constants as cs
 import dbus
-import time
 import BaseHTTPServer
 
 http_req = 0
diff --git a/tests/twisted/jingle/hold-audio.py b/tests/twisted/jingle/hold-audio.py
index 8bb0c03..810d3fe 100644
--- a/tests/twisted/jingle/hold-audio.py
+++ b/tests/twisted/jingle/hold-audio.py
@@ -4,7 +4,6 @@ Test the Hold API.
 
 from gabbletest import make_result_iq, sync_stream
 from servicetest import make_channel_proxy, call_async, EventPattern
-import ns
 import constants as cs
 
 from jingletest2 import JingleTest2, test_all_dialects
diff --git a/tests/twisted/jingle/hold-av.py b/tests/twisted/jingle/hold-av.py
index 32cf07f..e2bdc76 100644
--- a/tests/twisted/jingle/hold-av.py
+++ b/tests/twisted/jingle/hold-av.py
@@ -2,12 +2,8 @@
 Test the Hold API.
 """
 
-from gabbletest import exec_test, make_result_iq, acknowledge_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-import gabbletest
-import dbus
-import time
+from gabbletest import make_result_iq, sync_stream
+from servicetest import make_channel_proxy, call_async, EventPattern
 
 import constants as cs
 
diff --git a/tests/twisted/jingle/jingletest2.py b/tests/twisted/jingle/jingletest2.py
index 4fc0901..eede884 100644
--- a/tests/twisted/jingle/jingletest2.py
+++ b/tests/twisted/jingle/jingletest2.py
@@ -25,8 +25,8 @@ class JingleProtocol:
 
     def _simple_xml(self, node):
         "Construct domish.Element tree from tree of tuples"
-        name, ns, attribs, children = node
-        el = domish.Element((ns, name))
+        name, namespace, attribs, children = node
+        el = domish.Element((namespace, name))
         for key, val in attribs.items():
             el[key] = val
         for c in children:
@@ -238,12 +238,12 @@ class JingleProtocol015(JingleProtocol):
 
     def Description(self, type, children):
         if type == 'audio':
-            ns = 'http://jabber.org/protocol/jingle/description/audio'
+            namespace = 'http://jabber.org/protocol/jingle/description/audio'
         elif type == 'video':
-            ns = 'http://jabber.org/protocol/jingle/description/video'
+            namespace = 'http://jabber.org/protocol/jingle/description/video'
         else:
-            ns = 'unexistent-namespace'
-        return ('description', ns, { 'type': type }, children)
+            namespace = 'unexistent-namespace'
+        return ('description', namespace, { 'type': type }, children)
 
 class JingleProtocol031(JingleProtocol):
     features = [ 'urn:xmpp:jingle:0', 'urn:xmpp:jingle:apps:rtp:0',
diff --git a/tests/twisted/jingle/outgoing-many-streams.py b/tests/twisted/jingle/outgoing-many-streams.py
index 8a54581..93e8b5d 100644
--- a/tests/twisted/jingle/outgoing-many-streams.py
+++ b/tests/twisted/jingle/outgoing-many-streams.py
@@ -4,14 +4,13 @@ Test making outgoing call using CreateChannel. This tests the happy scenario
 when the remote party accepts the call.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish
+import dbus
+
+from gabbletest import exec_test, sync_stream
+from servicetest import (
+    make_channel_proxy, tp_path_prefix, call_async, EventPattern)
 import jingletest
 import gabbletest
-import dbus
-import time
 
 import constants as cs
 
@@ -124,7 +123,7 @@ def test(q, bus, conn, stream):
     assert handle not in group_props['Members'], group_props
 
     list_streams_result = media_iface.ListStreams()
-    assert len(list_streams_result) == 0, streams
+    assert len(list_streams_result) == 0, list_streams_result
 
     # Asking for 4 audio and 3 video streams is pathological, but we claim to
     # support up to 99 streams, so we should test a decent number of them.
diff --git a/tests/twisted/jingle/payload-types.py b/tests/twisted/jingle/payload-types.py
index cddfe6b..2a0b05a 100644
--- a/tests/twisted/jingle/payload-types.py
+++ b/tests/twisted/jingle/payload-types.py
@@ -2,18 +2,15 @@
 Regression test for https://bugs.freedesktop.org/show_bug.cgi?id=18918
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, \
-        send_error_reply
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish
-import jingletest
-import gabbletest
 import dbus
-import time
 
+from gabbletest import exec_test, sync_stream
+from servicetest import make_channel_proxy
+import jingletest
 import constants as cs
 
+from twisted.words.xish import domish
+
 def test(q, bus, conn, stream):
     jt = jingletest.JingleTest(stream, 'test at localhost', 'foo at bar.com/Foo')
 
diff --git a/tests/twisted/jingle/stream-handler-error.py b/tests/twisted/jingle/stream-handler-error.py
index 0f6f73a..27c2f90 100644
--- a/tests/twisted/jingle/stream-handler-error.py
+++ b/tests/twisted/jingle/stream-handler-error.py
@@ -5,7 +5,7 @@ masking refcounting assumptions.
 """
 
 from gabbletest import exec_test
-from servicetest import make_channel_proxy, tp_path_prefix, EventPattern
+from servicetest import make_channel_proxy
 import jingletest
 
 import constants as cs
diff --git a/tests/twisted/jingle/stun-server.py b/tests/twisted/jingle/stun-server.py
index 224f8f0..dad8724 100644
--- a/tests/twisted/jingle/stun-server.py
+++ b/tests/twisted/jingle/stun-server.py
@@ -2,15 +2,12 @@
 Test getting STUN server from Google jingleinfo
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, \
-        GoogleXmlStream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern
-import jingletest
-import gabbletest
-import constants as c
 import dbus
-import time
+
+from gabbletest import exec_test, make_result_iq, sync_stream, GoogleXmlStream
+from servicetest import make_channel_proxy, tp_path_prefix, EventPattern
+import jingletest
+import constants as cs
 
 def test(q, bus, conn, stream,
          expected_stun_server=None, expected_stun_port=None, google=False,
@@ -69,7 +66,7 @@ def test(q, bus, conn, stream,
 
     # We're pending because of remote_handle
     e = q.expect('dbus-signal', signal='MembersChanged',
-             args=[u'', [], [], [1L], [], remote_handle, c.GC_REASON_INVITED])
+             args=[u'', [], [], [1L], [], remote_handle, cs.GC_REASON_INVITED])
 
     # S-E gets notified about new session handler, and calls Ready on it
     e = q.expect('dbus-signal', signal='NewSessionHandler')
@@ -118,7 +115,7 @@ def test(q, bus, conn, stream,
                 dbus_interface=dbus.PROPERTIES_IFACE), k
 
     # The old API for STUN servers etc. still needs supporting, for farsight 1
-    tp_prop_list = media_chan.ListProperties(dbus_interface=c.TP_AWKWARD_PROPERTIES)
+    tp_prop_list = media_chan.ListProperties(dbus_interface=cs.TP_AWKWARD_PROPERTIES)
     tp_props = {}
     tp_prop_ids = {}
 
@@ -128,7 +125,7 @@ def test(q, bus, conn, stream,
 
     assert 'nat-traversal' in tp_props
     assert tp_props['nat-traversal']['sig'] == 's'
-    assert tp_props['nat-traversal']['flags'] == c.PROPERTY_FLAG_READ
+    assert tp_props['nat-traversal']['flags'] == cs.PROPERTY_FLAG_READ
     assert 'stun-server' in tp_props
     assert tp_props['stun-server']['sig'] == 's'
     assert 'stun-port' in tp_props
@@ -139,21 +136,21 @@ def test(q, bus, conn, stream,
     if expected_stun_server is None:
         assert tp_props['stun-server']['flags'] == 0
     else:
-        assert tp_props['stun-server']['flags'] == c.PROPERTY_FLAG_READ
+        assert tp_props['stun-server']['flags'] == cs.PROPERTY_FLAG_READ
 
     if expected_stun_port is None:
         assert tp_props['stun-port']['flags'] == 0
     else:
-        assert tp_props['stun-port']['flags'] == c.PROPERTY_FLAG_READ
+        assert tp_props['stun-port']['flags'] == cs.PROPERTY_FLAG_READ
 
     if google:
-        assert tp_props['gtalk-p2p-relay-token']['flags'] == c.PROPERTY_FLAG_READ
+        assert tp_props['gtalk-p2p-relay-token']['flags'] == cs.PROPERTY_FLAG_READ
     else:
         assert tp_props['gtalk-p2p-relay-token']['flags'] == 0
 
     tp_prop_values = media_chan.GetProperties(
             [tp_props[k]['id'] for k in tp_props if tp_props[k]['flags']],
-            dbus_interface=c.TP_AWKWARD_PROPERTIES)
+            dbus_interface=cs.TP_AWKWARD_PROPERTIES)
 
     for value in tp_prop_values:
         assert value[0] in tp_prop_ids
diff --git a/tests/twisted/jingle/test-content-adding-removal.py b/tests/twisted/jingle/test-content-adding-removal.py
index a707e78..707a3c8 100644
--- a/tests/twisted/jingle/test-content-adding-removal.py
+++ b/tests/twisted/jingle/test-content-adding-removal.py
@@ -5,17 +5,12 @@ the first one and lastly remove the second stream, which
 closes the session.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, \
-        send_error_reply
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish, xpath
+from gabbletest import exec_test, make_result_iq, sync_stream
+from servicetest import make_channel_proxy, tp_path_prefix
 import jingletest
-import gabbletest
-import dbus
-import time
-from constants import *
+import constants as cs
 
+from twisted.words.xish import domish, xpath
 
 def test(q, bus, conn, stream):
     jt = jingletest.JingleTest(stream, 'test at localhost', 'foo at bar.com/Foo')
@@ -56,7 +51,7 @@ def test(q, bus, conn, stream):
 
     # This is the interesting part of this test
 
-    media_iface.RequestStreams(handle, [MEDIA_STREAM_TYPE_AUDIO])
+    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_AUDIO])
 
     # S-E gets notified about new session handler, and calls Ready on it
     e = q.expect('dbus-signal', signal='NewSessionHandler')
@@ -74,7 +69,7 @@ def test(q, bus, conn, stream):
 
     # Before sending the initiate, request another stream
 
-    media_iface.RequestStreams(handle, [MEDIA_STREAM_TYPE_VIDEO])
+    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
 
     e = q.expect('dbus-signal', signal='NewStreamHandler')
     stream_id2 = e.args[1]
@@ -83,9 +78,9 @@ def test(q, bus, conn, stream):
 
     # We set both streams as ready, which will trigger the session invite
     stream_handler.Ready(jt.get_audio_codecs_dbus())
-    stream_handler.StreamState(MEDIA_STREAM_STATE_CONNECTED)
+    stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
     stream_handler2.Ready(jt.get_audio_codecs_dbus())
-    stream_handler2.StreamState(MEDIA_STREAM_STATE_CONNECTED)
+    stream_handler2.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
 
     # We changed our mind locally, don't want video
     media_iface.RemoveStreams([stream_id2])
@@ -93,7 +88,7 @@ def test(q, bus, conn, stream):
     e = q.expect('stream-iq')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'session-initiate'
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     e2 = q.expect('stream-iq', predicate=lambda x:
         xpath.queryForNodes("/iq/jingle[@action='content-remove']",
@@ -107,11 +102,11 @@ def test(q, bus, conn, stream):
     # now. If it's good, stream will be really removed, and
     # we can proceed.
 
-    stream.send(gabbletest.make_result_iq(stream, e2.stanza))
+    stream.send(make_result_iq(stream, e2.stanza))
 
     q.expect('dbus-signal', signal='StreamRemoved')
 
-    media_iface.RequestStreams(handle, [MEDIA_STREAM_TYPE_VIDEO])
+    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
 
     e = q.expect('dbus-signal', signal='NewStreamHandler')
     stream2_id = e.args[1]
@@ -120,14 +115,14 @@ def test(q, bus, conn, stream):
 
     stream_handler2.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
     stream_handler2.Ready(jt.get_audio_codecs_dbus())
-    stream_handler2.StreamState(MEDIA_STREAM_STATE_CONNECTED)
+    stream_handler2.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
 
     e = q.expect('stream-iq')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'content-add'
     c = e.query.firstChildElement ()
     assert c['creator'] == 'initiator', c['creator'] + " should be initiator"
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     iq, jingle = jt._jingle_stanza('content-accept')
 
@@ -160,7 +155,7 @@ def test(q, bus, conn, stream):
     e = q.expect('stream-iq', iq_type='set')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'content-remove'
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     # Then we remove the second stream, which terminates the session
     media_iface.RemoveStreams([stream2_id])
@@ -168,7 +163,7 @@ def test(q, bus, conn, stream):
     e = q.expect('stream-iq')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'session-terminate'
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     # Now the session should be terminated
 
diff --git a/tests/twisted/jingle/test-content-complex.py b/tests/twisted/jingle/test-content-complex.py
index de978c4..cd4ced6 100644
--- a/tests/twisted/jingle/test-content-complex.py
+++ b/tests/twisted/jingle/test-content-complex.py
@@ -2,18 +2,13 @@
 Test everything related to contents
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, exec_tests
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern
-import gabbletest
-import dbus
-import time
-from twisted.words.xish import xpath
-
+from servicetest import make_channel_proxy, tp_path_prefix
 import constants as cs
 from jingletest2 import (
     JingleTest2, JingleProtocol015, JingleProtocol031, test_dialects)
 
+from twisted.words.xish import xpath
+
 def worker(jp, q, bus, conn, stream):
 
     def make_stream_request(stream_type):
diff --git a/tests/twisted/jingle/test-description-info.py b/tests/twisted/jingle/test-description-info.py
index 8f0234c..7437e15 100644
--- a/tests/twisted/jingle/test-description-info.py
+++ b/tests/twisted/jingle/test-description-info.py
@@ -2,17 +2,14 @@
 Test emition and handling of codec update using description-info
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, exec_tests
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern, call_async
-import gabbletest
-import dbus
-import time
-from twisted.words.xish import xpath
+from gabbletest import exec_test
+from servicetest import (
+    make_channel_proxy, unwrap, tp_path_prefix, EventPattern, call_async)
+from jingletest2 import JingleTest2, JingleProtocol031
+import constants as cs
 
-from jingletest2 import *
+from twisted.words.xish import xpath
 
-import constants as cs
 
 def extract_params(payload_type):
     ret = {}
diff --git a/tests/twisted/jingle/test-dialects-incoming.py b/tests/twisted/jingle/test-dialects-incoming.py
index 4cecbce..d1e7df3 100644
--- a/tests/twisted/jingle/test-dialects-incoming.py
+++ b/tests/twisted/jingle/test-dialects-incoming.py
@@ -2,17 +2,11 @@
 Test incoming call handling.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, exec_tests
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern
-import gabbletest
-import dbus
-import time
-from twisted.words.xish import xpath
-
+from servicetest import make_channel_proxy, tp_path_prefix
 import constants as cs
+from jingletest2 import JingleTest2, test_all_dialects
 
-from jingletest2 import *
+from twisted.words.xish import xpath
 
 def worker(jp, q, bus, conn, stream):
 
diff --git a/tests/twisted/jingle/test-dialects-outgoing.py b/tests/twisted/jingle/test-dialects-outgoing.py
index 141ac2c..4639b1e 100644
--- a/tests/twisted/jingle/test-dialects-outgoing.py
+++ b/tests/twisted/jingle/test-dialects-outgoing.py
@@ -2,17 +2,12 @@
 Test outgoing call handling.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream, exec_tests
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern, call_async
-import gabbletest
 import dbus
-import time
 from twisted.words.xish import xpath
 
+from servicetest import make_channel_proxy, EventPattern, call_async
 import constants as cs
-
-from jingletest2 import *
+from jingletest2 import JingleTest2, test_all_dialects
 
 def worker(jp, q, bus, conn, stream):
 
diff --git a/tests/twisted/jingle/test-incoming-call.py b/tests/twisted/jingle/test-incoming-call.py
index 89f0619..f473177 100644
--- a/tests/twisted/jingle/test-incoming-call.py
+++ b/tests/twisted/jingle/test-incoming-call.py
@@ -2,14 +2,12 @@
 Test incoming call handling.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        EventPattern, sync_dbus
-import jingletest
-import gabbletest
 import dbus
-import time
 
+from gabbletest import exec_test, make_result_iq, sync_stream
+from servicetest import (
+    make_channel_proxy, unwrap, tp_path_prefix, EventPattern, sync_dbus)
+import jingletest
 import constants as cs
 
 def test(q, bus, conn, stream):
@@ -140,7 +138,7 @@ def test(q, bus, conn, stream):
     assert e.query['action'] == 'transport-info'
     assert e.query['initiator'] == 'foo at bar.com/Foo'
 
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     # Make sure everything's processed
     sync_stream(q, stream)
diff --git a/tests/twisted/jingle/test-outgoing-call-deprecated.py b/tests/twisted/jingle/test-outgoing-call-deprecated.py
index 2d75657..67649c2 100644
--- a/tests/twisted/jingle/test-outgoing-call-deprecated.py
+++ b/tests/twisted/jingle/test-outgoing-call-deprecated.py
@@ -4,12 +4,11 @@ Test outgoing call handling. This tests the happy scenario
 when the remote party accepts the call.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix
+from gabbletest import exec_test, sync_stream
+from servicetest import make_channel_proxy
 import jingletest
 import gabbletest
 import dbus
-import time
 
 import constants as cs
 
diff --git a/tests/twisted/jingle/test-outgoing-call-deprecated2.py b/tests/twisted/jingle/test-outgoing-call-deprecated2.py
index 43c0f11..6b245b3 100644
--- a/tests/twisted/jingle/test-outgoing-call-deprecated2.py
+++ b/tests/twisted/jingle/test-outgoing-call-deprecated2.py
@@ -4,12 +4,11 @@ Test outgoing call handling. This tests the happy scenario
 when the remote party accepts the call.
 """
 
+import dbus
+
 from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix
+from servicetest import make_channel_proxy
 import jingletest
-import gabbletest
-import dbus
-import time
 
 import constants as cs
 
@@ -85,7 +84,7 @@ def test(q, bus, conn, stream):
     e = q.expect('stream-iq')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'session-initiate'
-    stream.send(gabbletest.make_result_iq(stream, e.stanza))
+    stream.send(make_result_iq(stream, e.stanza))
 
     jt.outgoing_call_reply(e.query['sid'], True)
 
diff --git a/tests/twisted/jingle/test-outgoing-call-ensure.py b/tests/twisted/jingle/test-outgoing-call-ensure.py
index 3364f85..afedcc5 100644
--- a/tests/twisted/jingle/test-outgoing-call-ensure.py
+++ b/tests/twisted/jingle/test-outgoing-call-ensure.py
@@ -4,14 +4,9 @@ Test making outgoing calls using EnsureChannel, and retrieving existing calls
 using EnsureChannel.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish
+from gabbletest import exec_test, sync_stream
+from servicetest import make_channel_proxy, call_async, EventPattern
 import jingletest
-import gabbletest
-import dbus
-import time
 
 
 def test(q, bus, conn, stream):
@@ -136,8 +131,8 @@ def test(q, bus, conn, stream):
     assert old_sig.args[0] == path, (old_sig.args[0], path)
     assert old_sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.StreamedMedia',\
             old_sig.args[1]
-    assert old_sig.args[2] == 0, sig.args[2]
-    assert old_sig.args[3] == 0, sig.args[3]
+    assert old_sig.args[2] == 0, old_sig.args[2]
+    assert old_sig.args[3] == 0, old_sig.args[3]
     assert old_sig.args[4] == True      # suppress handler
 
     assert len(new_sig.args) == 1
diff --git a/tests/twisted/jingle/test-outgoing-call-rejected.py b/tests/twisted/jingle/test-outgoing-call-rejected.py
index 22ef2df..ee27ed4 100644
--- a/tests/twisted/jingle/test-outgoing-call-rejected.py
+++ b/tests/twisted/jingle/test-outgoing-call-rejected.py
@@ -4,9 +4,8 @@ remote party rejects our call because they're busy.
 """
 
 from gabbletest import make_result_iq
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix
+from servicetest import make_channel_proxy
 import constants as cs
-
 from jingletest2 import JingleTest2, test_all_dialects
 
 def test(jp, q, bus, conn, stream):
diff --git a/tests/twisted/jingle/test-outgoing-call-requestotron.py b/tests/twisted/jingle/test-outgoing-call-requestotron.py
index 12d90f2..d438fb3 100644
--- a/tests/twisted/jingle/test-outgoing-call-requestotron.py
+++ b/tests/twisted/jingle/test-outgoing-call-requestotron.py
@@ -4,14 +4,12 @@ Test making outgoing call using CreateChannel. This tests the happy scenario
 when the remote party accepts the call.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish
+import dbus
+
+from gabbletest import exec_test, sync_stream
+from servicetest import make_channel_proxy, call_async, EventPattern
 import jingletest
 import gabbletest
-import dbus
-import time
 
 import constants as cs
 
@@ -142,7 +140,7 @@ def test(q, bus, conn, stream):
     assert handle not in group_props['Members'], group_props
 
     list_streams_result = media_iface.ListStreams()
-    assert len(list_streams_result) == 0, streams
+    assert len(list_streams_result) == 0, list_streams_result
 
     streams = media_iface.RequestStreams(handle,
             [cs.MEDIA_STREAM_TYPE_AUDIO])
diff --git a/tests/twisted/jingle/test-outgoing-call.py b/tests/twisted/jingle/test-outgoing-call.py
index 24e1155..4b08979 100644
--- a/tests/twisted/jingle/test-outgoing-call.py
+++ b/tests/twisted/jingle/test-outgoing-call.py
@@ -4,14 +4,11 @@ Test outgoing call handling. This tests the happy scenario
 when the remote party accepts the call.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
-        call_async, EventPattern
-from twisted.words.xish import domish
+from gabbletest import exec_test, sync_stream
+from servicetest import make_channel_proxy, call_async, EventPattern
 import jingletest
 import gabbletest
 import dbus
-import time
 
 import constants as cs
 
@@ -61,8 +58,8 @@ def test(q, bus, conn, stream):
     assert old_sig.args[0] == path, (old_sig.args[0], path)
     assert old_sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.StreamedMedia',\
             old_sig.args[1]
-    assert old_sig.args[2] == 0, sig.args[2]
-    assert old_sig.args[3] == 0, sig.args[3]
+    assert old_sig.args[2] == 0, old_sig.args[2]
+    assert old_sig.args[3] == 0, old_sig.args[3]
     assert old_sig.args[4] == True      # suppress handler
 
     assert len(new_sig.args) == 1
@@ -129,7 +126,7 @@ def test(q, bus, conn, stream):
     assert 'GroupFlags' in group_props, group_props
 
     list_streams_result = media_iface.ListStreams()
-    assert len(list_streams_result) == 0, streams
+    assert len(list_streams_result) == 0, list_streams_result
 
     streams = media_iface.RequestStreams(handle,
             [cs.MEDIA_STREAM_TYPE_AUDIO])
diff --git a/tests/twisted/presence/presence.py b/tests/twisted/presence/presence.py
index 96f945b..2c2f211 100644
--- a/tests/twisted/presence/presence.py
+++ b/tests/twisted/presence/presence.py
@@ -4,9 +4,7 @@ A simple smoke-test for C.I.SimplePresence
 FIXME: test C.I.Presence too
 """
 
-import dbus
-
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import domish
 
 from gabbletest import exec_test
 
diff --git a/tests/twisted/roster/ensure.py b/tests/twisted/roster/ensure.py
index f75ee93..6e4c488 100644
--- a/tests/twisted/roster/ensure.py
+++ b/tests/twisted/roster/ensure.py
@@ -2,13 +2,9 @@
 Test ensuring roster channels
 """
 
-import dbus
-
-from gabbletest import exec_test, sync_stream
-from servicetest import sync_dbus, call_async
-
-HT_CONTACT_LIST = 3
-HT_GROUP = 4
+from gabbletest import exec_test
+from servicetest import call_async
+import constants as cs
 
 def test(q, bus, conn, stream):
     conn.Connect()
@@ -17,7 +13,7 @@ def test(q, bus, conn, stream):
     roster_event = q.expect('stream-iq', query_ns='jabber:iq:roster')
     roster_event.stanza['type'] = 'result'
 
-    call_async(q, conn, "RequestHandles", HT_GROUP, ['test'])
+    call_async(q, conn, "RequestHandles", cs.HT_GROUP, ['test'])
 
     event = q.expect('dbus-return', method='RequestHandles')
     test_handle = event.value[0][0]
@@ -28,13 +24,13 @@ def test(q, bus, conn, stream):
     call_async(q, conn.Requests, 'EnsureChannel',
             { 'org.freedesktop.Telepathy.Channel.ChannelType':
                 'org.freedesktop.Telepathy.Channel.Type.ContactList',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': HT_GROUP,
+              'org.freedesktop.Telepathy.Channel.TargetHandleType': cs.HT_GROUP,
               'org.freedesktop.Telepathy.Channel.TargetHandle': test_handle,
               })
     call_async(q, conn.Requests, 'EnsureChannel',
             { 'org.freedesktop.Telepathy.Channel.ChannelType':
                 'org.freedesktop.Telepathy.Channel.Type.ContactList',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': HT_GROUP,
+              'org.freedesktop.Telepathy.Channel.TargetHandleType': cs.HT_GROUP,
               'org.freedesktop.Telepathy.Channel.TargetHandle': test_handle,
               })
 
@@ -51,7 +47,7 @@ def test(q, bus, conn, stream):
     assert props['org.freedesktop.Telepathy.Channel.ChannelType'] ==\
             'org.freedesktop.Telepathy.Channel.Type.ContactList', props
     assert props['org.freedesktop.Telepathy.Channel.TargetHandleType'] ==\
-            HT_GROUP, props
+            cs.HT_GROUP, props
     assert props['org.freedesktop.Telepathy.Channel.TargetHandle'] ==\
             test_handle, props
     assert props['org.freedesktop.Telepathy.Channel.TargetID'] ==\
diff --git a/tests/twisted/roster/request-group-after-roster.py b/tests/twisted/roster/request-group-after-roster.py
index 56be251..ba49b91 100644
--- a/tests/twisted/roster/request-group-after-roster.py
+++ b/tests/twisted/roster/request-group-after-roster.py
@@ -3,13 +3,9 @@ Regression test for a bug where CreateChannel times out when requesting a group
 channel after the roster has been received.
 """
 
-import dbus
-
 from gabbletest import exec_test, sync_stream
 from servicetest import sync_dbus, call_async
-
-HT_CONTACT_LIST = 3
-HT_GROUP = 4
+import constants as cs
 
 def test(q, bus, conn, stream):
     conn.Connect()
@@ -18,7 +14,7 @@ def test(q, bus, conn, stream):
     roster_event = q.expect('stream-iq', query_ns='jabber:iq:roster')
     roster_event.stanza['type'] = 'result'
 
-    call_async(q, conn, "RequestHandles", HT_GROUP, ['test'])
+    call_async(q, conn, "RequestHandles", cs.HT_GROUP, ['test'])
 
     event = q.expect('dbus-return', method='RequestHandles')
     test_handle = event.value[0][0]
@@ -32,7 +28,8 @@ def test(q, bus, conn, stream):
     call_async(q, conn.Requests, 'CreateChannel',
             { 'org.freedesktop.Telepathy.Channel.ChannelType':
                 'org.freedesktop.Telepathy.Channel.Type.ContactList',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': HT_GROUP,
+              'org.freedesktop.Telepathy.Channel.TargetHandleType':
+                 cs.HT_GROUP,
               'org.freedesktop.Telepathy.Channel.TargetHandle': test_handle,
               })
 
@@ -44,7 +41,7 @@ def test(q, bus, conn, stream):
     assert props['org.freedesktop.Telepathy.Channel.ChannelType'] ==\
             'org.freedesktop.Telepathy.Channel.Type.ContactList', props
     assert props['org.freedesktop.Telepathy.Channel.TargetHandleType'] ==\
-            HT_GROUP, props
+            cs.HT_GROUP, props
     assert props['org.freedesktop.Telepathy.Channel.TargetHandle'] ==\
             test_handle, props
     assert props['org.freedesktop.Telepathy.Channel.TargetID'] ==\
diff --git a/tests/twisted/roster/request-group-before-roster.py b/tests/twisted/roster/request-group-before-roster.py
index e764bdc..fe3a8e0 100644
--- a/tests/twisted/roster/request-group-before-roster.py
+++ b/tests/twisted/roster/request-group-before-roster.py
@@ -3,8 +3,6 @@ Regression test for a bug where RequestChannel times out when requesting a
 group channel if the roster hasn't been received at the time of the call.
 """
 
-import dbus
-
 from gabbletest import exec_test, sync_stream
 from servicetest import sync_dbus, call_async
 
diff --git a/tests/twisted/roster/test-google-roster.py b/tests/twisted/roster/test-google-roster.py
index b77415e..b1b9248 100644
--- a/tests/twisted/roster/test-google-roster.py
+++ b/tests/twisted/roster/test-google-roster.py
@@ -4,14 +4,11 @@ Test workarounds for gtalk
 """
 
 import dbus
-import sys
 
-from twisted.words.xish import domish
-
-from servicetest import EventPattern
 from gabbletest import acknowledge_iq, exec_test
 
 from twisted.words.protocols.jabber.client import IQ
+from twisted.words.xish import domish
 
 def make_set_roster_iq(stream, user, contact, state, ask):
     iq = IQ(stream, 'set')
diff --git a/tests/twisted/roster/test-roster-item-deletion.py b/tests/twisted/roster/test-roster-item-deletion.py
index c7fd926..1add452 100644
--- a/tests/twisted/roster/test-roster-item-deletion.py
+++ b/tests/twisted/roster/test-roster-item-deletion.py
@@ -6,7 +6,7 @@ import dbus
 
 from twisted.words.protocols.jabber.client import IQ
 from gabbletest import exec_test, acknowledge_iq
-from servicetest import EventPattern, tp_name_prefix
+from servicetest import EventPattern
 
 def _expect_contact_list_channel(q, bus, conn, name, contacts):
     old_signal, new_signal = q.expect_many(
diff --git a/tests/twisted/test-capabilities.py b/tests/twisted/test-capabilities.py
index 1540833..496c914 100644
--- a/tests/twisted/test-capabilities.py
+++ b/tests/twisted/test-capabilities.py
@@ -5,8 +5,6 @@ Test capabilities.
 
 import dbus
 
-from twisted.words.xish import domish
-
 from servicetest import EventPattern
 from gabbletest import exec_test, make_result_iq, make_presence
 
diff --git a/tests/twisted/test-caps-cache.py b/tests/twisted/test-caps-cache.py
index 98ef5e6..9ab0c04 100644
--- a/tests/twisted/test-caps-cache.py
+++ b/tests/twisted/test-caps-cache.py
@@ -4,10 +4,7 @@ Test that requesting a caps set 1 time is enough with hash and that we need 5
 confirmation without hash.
 """
 
-import dbus
-import sys
-
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 
 from servicetest import EventPattern
 from gabbletest import exec_test, make_result_iq, make_presence
diff --git a/tests/twisted/test-caps-hash.py b/tests/twisted/test-caps-hash.py
index 8548dd9..9e2baae 100644
--- a/tests/twisted/test-caps-hash.py
+++ b/tests/twisted/test-caps-hash.py
@@ -21,9 +21,8 @@ Then, this test announce 2 contacts with the same hash.
 """
 
 import dbus
-import sys
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 
 from gabbletest import exec_test, make_result_iq, make_presence
 from servicetest import sync_dbus, EventPattern
diff --git a/tests/twisted/test-disco-no-reply.py b/tests/twisted/test-disco-no-reply.py
index 4887952..2b3b010 100644
--- a/tests/twisted/test-disco-no-reply.py
+++ b/tests/twisted/test-disco-no-reply.py
@@ -4,8 +4,6 @@ Test that Gabble disconnects connection if it doesn't receive a response
 to its service discovery request
 """
 
-from twisted.words.xish import domish
-
 from gabbletest import exec_test, JabberXmlStream
 
 def test(q, bus, conn, stream):
diff --git a/tests/twisted/test-location.py b/tests/twisted/test-location.py
index 00f99ed..5dbdfca 100644
--- a/tests/twisted/test-location.py
+++ b/tests/twisted/test-location.py
@@ -1,7 +1,7 @@
 from gabbletest import exec_test, make_result_iq
 from servicetest import call_async, EventPattern
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 import constants as cs
 
 location_iface = \
diff --git a/tests/twisted/text/ensure.py b/tests/twisted/text/ensure.py
index f83c112..6722967 100644
--- a/tests/twisted/text/ensure.py
+++ b/tests/twisted/text/ensure.py
@@ -4,8 +4,6 @@ Test text channel initiated by me, using Requests.EnsureChannel
 
 import dbus
 
-from twisted.words.xish import domish
-
 from gabbletest import exec_test
 from servicetest import call_async, EventPattern
 
diff --git a/tests/twisted/text/initiate-requestotron.py b/tests/twisted/text/initiate-requestotron.py
index 6a69b27..9436693 100644
--- a/tests/twisted/text/initiate-requestotron.py
+++ b/tests/twisted/text/initiate-requestotron.py
@@ -4,8 +4,6 @@ Test text channel initiated by me, using Requests.
 
 import dbus
 
-from twisted.words.xish import domish
-
 from gabbletest import exec_test
 from servicetest import call_async, EventPattern
 
diff --git a/tests/twisted/text/send-error.py b/tests/twisted/text/send-error.py
index a1fc423..5008e84 100644
--- a/tests/twisted/text/send-error.py
+++ b/tests/twisted/text/send-error.py
@@ -3,8 +3,6 @@ Test that an incoming <message><error/></> for a contact gives both a SendError
 and a delivery report on a 1-1 text channel to that contact.
 """
 
-import dbus
-
 from twisted.words.xish import domish
 
 from gabbletest import exec_test
diff --git a/tests/twisted/text/test-chat-state.py b/tests/twisted/text/test-chat-state.py
index ec92a8e..d72b1ac 100644
--- a/tests/twisted/text/test-chat-state.py
+++ b/tests/twisted/text/test-chat-state.py
@@ -4,8 +4,6 @@ Test that chat state notifications are correctly sent and received on text
 channels.
 """
 
-import dbus
-
 from twisted.words.xish import domish
 
 from servicetest import call_async, make_channel_proxy
diff --git a/tests/twisted/text/test-text-delayed.py b/tests/twisted/text/test-text-delayed.py
index b0ac215..519a950 100644
--- a/tests/twisted/text/test-text-delayed.py
+++ b/tests/twisted/text/test-text-delayed.py
@@ -45,9 +45,9 @@ def test(q, bus, conn, stream):
     header = message[0]
     message_sent_timestamp = header['message-sent']
     assert str(datetime.datetime.utcfromtimestamp(message_sent_timestamp)
-        == '2007-05-17 16:15:01'), headers
+        == '2007-05-17 16:15:01'), header
     message_received_timestamp = header['message-received']
-    assert message_received_timestamp > message_sent_timestamp, headers
+    assert message_received_timestamp > message_sent_timestamp, header
 
     assert message[1]['content'] == 'hello', message
 
diff --git a/tests/twisted/tubes/accept-muc-dbus-tube.py b/tests/twisted/tubes/accept-muc-dbus-tube.py
index b39f747..695c3cf 100644
--- a/tests/twisted/tubes/accept-muc-dbus-tube.py
+++ b/tests/twisted/tubes/accept-muc-dbus-tube.py
@@ -4,7 +4,7 @@ from servicetest import call_async, EventPattern
 from gabbletest import exec_test, acknowledge_iq, make_muc_presence
 import constants as c
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 import ns
 
 from mucutil import join_muc_and_check
diff --git a/tests/twisted/tubes/accept-muc-stream-tube.py b/tests/twisted/tubes/accept-muc-stream-tube.py
index a21406e..2e5abdb 100644
--- a/tests/twisted/tubes/accept-muc-stream-tube.py
+++ b/tests/twisted/tubes/accept-muc-stream-tube.py
@@ -9,7 +9,7 @@ import ns
 import tubetestutil as t
 from bytestream import create_from_si_offer, announce_socks5_proxy, BytestreamS5BRelay, BytestreamS5BRelayBugged
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 from twisted.internet import reactor
 
 sample_parameters = dbus.Dictionary({
diff --git a/tests/twisted/tubes/close-muc-with-closed-tube.py b/tests/twisted/tubes/close-muc-with-closed-tube.py
index 647654a..a3f7c31 100644
--- a/tests/twisted/tubes/close-muc-with-closed-tube.py
+++ b/tests/twisted/tubes/close-muc-with-closed-tube.py
@@ -1,18 +1,13 @@
 """Test IBB stream tube support in the context of a MUC."""
 
-import base64
 import dbus
 
-from servicetest import call_async, EventPattern, tp_name_prefix, EventProtocolClientFactory
+from servicetest import call_async, EventPattern, tp_name_prefix, unwrap
 from gabbletest import exec_test, make_result_iq, acknowledge_iq, make_muc_presence
-from constants import *
+import constants as cs
 import ns
 import tubetestutil as t
 
-from twisted.words.xish import domish, xpath
-from twisted.internet import reactor
-from twisted.words.protocols.jabber.client import IQ
-
 sample_parameters = dbus.Dictionary({
     's': 'hello',
     'ay': dbus.ByteArray('hello'),
@@ -130,9 +125,9 @@ def test(q, bus, conn, stream):
     q.expect('dbus-signal', signal='NewTube',
         args=[tube_id, bob_handle, 0, 'org.telepathy.freedesktop.test', sample_parameters, 0])
 
-    expected_tube = (tube_id, bob_handle, TUBE_TYPE_DBUS,
+    expected_tube = (tube_id, bob_handle, cs.TUBE_TYPE_DBUS,
         'org.telepathy.freedesktop.test', sample_parameters,
-        TUBE_STATE_LOCAL_PENDING)
+        cs.TUBE_STATE_LOCAL_PENDING)
     tubes = tubes_iface.ListTubes(byte_arrays=True)
     assert len(tubes) == 1, unwrap(tubes)
     t.check_tube_in_tubes(expected_tube, tubes)
diff --git a/tests/twisted/tubes/crash-on-list-channels.py b/tests/twisted/tubes/crash-on-list-channels.py
index 1aa3426..3fe4c9d 100644
--- a/tests/twisted/tubes/crash-on-list-channels.py
+++ b/tests/twisted/tubes/crash-on-list-channels.py
@@ -5,13 +5,13 @@ DBus tube asserted.
 
 import dbus
 
-from servicetest import call_async, EventPattern, watch_tube_signals
-from gabbletest import exec_test, acknowledge_iq, sync_stream
+from servicetest import call_async, EventPattern
+from gabbletest import exec_test, sync_stream
 
 import ns
 import constants
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import domish
 
 jid = 'explosions at in.the.sky'
 
diff --git a/tests/twisted/tubes/create-invalid-tube-channels.py b/tests/twisted/tubes/create-invalid-tube-channels.py
index 0aed251..3bc8916 100644
--- a/tests/twisted/tubes/create-invalid-tube-channels.py
+++ b/tests/twisted/tubes/create-invalid-tube-channels.py
@@ -3,18 +3,17 @@ Check that Gabble rejects invalid requests for tubes channels.
 """
 
 import dbus
-from dbus import PROPERTIES_IFACE
 
 from servicetest import call_async
 from gabbletest import exec_test
-from constants import *
+import constants as cs
 
 def is_tube(path, props):
-    ct = props[CHANNEL_TYPE]
-    return ct in [CHANNEL_TYPE_STREAM_TUBE, CHANNEL_TYPE_DBUS_TUBE]
+    ct = props[cs.CHANNEL_TYPE]
+    return ct in [cs.CHANNEL_TYPE_STREAM_TUBE, cs.CHANNEL_TYPE_DBUS_TUBE]
 
 def check_no_tubes(conn_props):
-    channels = conn_props.Get(CONN_IFACE_REQUESTS, 'Channels')
+    channels = conn_props.Get(cs.CONN_IFACE_REQUESTS, 'Channels')
     tube_channels = filter(is_tube, channels)
     assert len(tube_channels) == 0, tube_channels
 
@@ -23,14 +22,14 @@ def test(q, bus, conn, stream):
 
     q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]),
 
-    conn_props = dbus.Interface(conn, PROPERTIES_IFACE)
+    conn_props = dbus.Interface(conn, cs.PROPERTIES_IFACE)
 
     # Try to CreateChannel with unknown properties
     # Gabble must return an error
     call_async(q, conn.Requests, 'CreateChannel',
-            {CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
-             TARGET_HANDLE_TYPE: HT_CONTACT,
-             TARGET_ID: "foo at example.com",
+            {cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAM_TUBE,
+             cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+             cs.TARGET_ID: "foo at example.com",
              'this.property.does.not.exist':
                 'this.value.should.not.exist'
             });
@@ -41,9 +40,9 @@ def test(q, bus, conn, stream):
     # Try to CreateChannel with missing properties ("Service")
     # Gabble must return an error
     call_async(q, conn.Requests, 'CreateChannel',
-            {CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
-             TARGET_HANDLE_TYPE: HT_CONTACT,
-             TARGET_ID: "foo at example.com",
+            {cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAM_TUBE,
+             cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+             cs.TARGET_ID: "foo at example.com",
             });
     ret = q.expect('dbus-error', method='CreateChannel')
 
diff --git a/tests/twisted/tubes/ensure-si-tube.py b/tests/twisted/tubes/ensure-si-tube.py
index bfbb174..2e800b2 100644
--- a/tests/twisted/tubes/ensure-si-tube.py
+++ b/tests/twisted/tubes/ensure-si-tube.py
@@ -2,22 +2,13 @@
 Test support for creating and retrieving 1-1 tubes with EnsureChannel
 """
 
-import base64
-import errno
-import os
-
 import dbus
-from dbus.connection import Connection
-from dbus.lowlevel import SignalMessage
 
-from servicetest import call_async, EventPattern, tp_name_prefix, watch_tube_signals
+from servicetest import call_async, EventPattern, tp_name_prefix
 from gabbletest import exec_test, acknowledge_iq
 import ns
 
-from twisted.words.xish import domish, xpath
-from twisted.internet.protocol import Factory, Protocol
-from twisted.internet import reactor
-from twisted.words.protocols.jabber.client import IQ
+from twisted.words.xish import domish
 
 import tubetestutil as t
 
diff --git a/tests/twisted/tubes/muctubeutil.py b/tests/twisted/tubes/muctubeutil.py
index 91d2762..a298eb7 100644
--- a/tests/twisted/tubes/muctubeutil.py
+++ b/tests/twisted/tubes/muctubeutil.py
@@ -1,11 +1,9 @@
 import dbus
 
 from servicetest import call_async, EventPattern, tp_name_prefix
-from gabbletest import make_result_iq, acknowledge_iq, make_muc_presence
+from gabbletest import make_result_iq, make_muc_presence
 import constants as cs
 
-from twisted.words.xish import domish, xpath
-
 def get_muc_tubes_channel(q, bus, conn, stream, muc_jid, anonymous=True):
     """
     Returns a singleton list containing the MUC's handle, a proxy for the Tubes
diff --git a/tests/twisted/tubes/offer-muc-dbus-tube.py b/tests/twisted/tubes/offer-muc-dbus-tube.py
index a60f7cb..9a5b645 100644
--- a/tests/twisted/tubes/offer-muc-dbus-tube.py
+++ b/tests/twisted/tubes/offer-muc-dbus-tube.py
@@ -7,12 +7,12 @@ from dbus.connection import Connection
 from dbus.lowlevel import SignalMessage
 
 from servicetest import call_async, EventPattern
-from gabbletest import exec_test, make_result_iq, acknowledge_iq, elem
-from constants import *
+from gabbletest import exec_test, acknowledge_iq, elem
 import ns
+import constants as cs
 import tubetestutil as t
 
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import xpath
 
 from mucutil import join_muc
 from muctubeutil import get_muc_tubes_channel
@@ -107,16 +107,16 @@ def test(q, bus, conn, stream):
         stream, 'chat at conf.localhost')
 
     # Exercise basic Channel Properties from spec 0.17.7
-    channel_props = tubes_chan.GetAll(CHANNEL,
+    channel_props = tubes_chan.GetAll(cs.CHANNEL,
             dbus_interface=dbus.PROPERTIES_IFACE)
     assert channel_props.get('TargetHandle') == handle,\
             (channel_props.get('TargetHandle'), handle)
     assert channel_props.get('TargetHandleType') == 2,\
             channel_props.get('TargetHandleType')
-    assert channel_props.get('ChannelType') == CHANNEL_TYPE_TUBES,\
+    assert channel_props.get('ChannelType') == cs.CHANNEL_TYPE_TUBES,\
             channel_props.get('ChannelType')
     assert 'Interfaces' in channel_props, channel_props
-    assert CHANNEL_IFACE_GROUP in channel_props['Interfaces'], \
+    assert cs.CHANNEL_IFACE_GROUP in channel_props['Interfaces'], \
             channel_props['Interfaces']
     assert channel_props['TargetID'] == 'chat at conf.localhost', channel_props
     assert channel_props['Requested'] == True
@@ -124,7 +124,7 @@ def test(q, bus, conn, stream):
     assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
 
     # Exercise Group Properties from spec 0.17.6 (in a basic way)
-    group_props = tubes_chan.GetAll(CHANNEL_IFACE_GROUP,
+    group_props = tubes_chan.GetAll(cs.CHANNEL_IFACE_GROUP,
             dbus_interface=dbus.PROPERTIES_IFACE)
     assert 'SelfHandle' in group_props, group_props
     assert 'HandleOwners' in group_props, group_props
@@ -134,7 +134,7 @@ def test(q, bus, conn, stream):
     assert 'GroupFlags' in group_props, group_props
 
     tubes_self_handle = tubes_chan.GetSelfHandle(
-        dbus_interface=CHANNEL_IFACE_GROUP)
+        dbus_interface=cs.CHANNEL_IFACE_GROUP)
     assert group_props['SelfHandle'] == tubes_self_handle
 
     # Offer a D-Bus tube (old API)
@@ -146,15 +146,15 @@ def test(q, bus, conn, stream):
         EventPattern('dbus-signal', signal='NewTube'),
         EventPattern('stream-presence', to='chat at conf.localhost/test'),
         EventPattern('dbus-return', method='OfferDBusTube'),
-        EventPattern('dbus-signal', signal='DBusNamesChanged', interface=CHANNEL_TYPE_TUBES))
+        EventPattern('dbus-signal', signal='DBusNamesChanged', interface=cs.CHANNEL_TYPE_TUBES))
 
     # handle new_tube_event
     dbus_tube_id = new_tube_event.args[0]
     assert new_tube_event.args[1] == tubes_self_handle
-    assert new_tube_event.args[2] == TUBE_TYPE_DBUS
+    assert new_tube_event.args[2] == cs.TUBE_TYPE_DBUS
     assert new_tube_event.args[3] == 'com.example.TestCase'
     assert new_tube_event.args[4] == sample_parameters
-    assert new_tube_event.args[5] == TUBE_STATE_OPEN
+    assert new_tube_event.args[5] == cs.TUBE_STATE_OPEN
 
     # handle offer_return_event
     assert offer_return_event.value[0] == dbus_tube_id
@@ -174,8 +174,8 @@ def test(q, bus, conn, stream):
 
     tubes = tubes_iface.ListTubes(byte_arrays=True)
     assert len(tubes) == 1
-    expected_tube = (dbus_tube_id, tubes_self_handle, TUBE_TYPE_DBUS,
-        'com.example.TestCase', sample_parameters, TUBE_STATE_OPEN)
+    expected_tube = (dbus_tube_id, tubes_self_handle, cs.TUBE_TYPE_DBUS,
+        'com.example.TestCase', sample_parameters, cs.TUBE_STATE_OPEN)
     t.check_tube_in_tubes(expected_tube, tubes)
 
     dbus_tube_adr = tubes_iface.GetDBusTubeAddress(dbus_tube_id)
@@ -185,10 +185,10 @@ def test(q, bus, conn, stream):
     # offer a D-Bus tube to another room using new API
     muc = 'chat2 at conf.localhost'
     request = {
-        CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE,
-        TARGET_HANDLE_TYPE: HT_ROOM,
-        TARGET_ID: 'chat2 at conf.localhost',
-        DBUS_TUBE_SERVICE_NAME: 'com.example.TestCase',
+        cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
+        cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
+        cs.TARGET_ID: 'chat2 at conf.localhost',
+        cs.DBUS_TUBE_SERVICE_NAME: 'com.example.TestCase',
     }
     join_muc(q, bus, conn, stream, muc, request=request)
 
@@ -198,23 +198,23 @@ def test(q, bus, conn, stream):
     assert len(channels) == 2
     path1, prop1 = channels[0]
     path2, prop2 = channels[1]
-    assert sorted([prop1[CHANNEL_TYPE], prop2[CHANNEL_TYPE]]) == \
-        [CHANNEL_TYPE_TEXT, CHANNEL_TYPE_TUBES]
+    assert sorted([prop1[cs.CHANNEL_TYPE], prop2[cs.CHANNEL_TYPE]]) == \
+        [cs.CHANNEL_TYPE_TEXT, cs.CHANNEL_TYPE_TUBES]
 
     got_text, got_tubes = False, False
     for path, props in channels:
-        if props[CHANNEL_TYPE] == CHANNEL_TYPE_TEXT:
+        if props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT:
             got_text = True
-        elif props[CHANNEL_TYPE] == CHANNEL_TYPE_TUBES:
+        elif props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TUBES:
             got_tubes = True
         else:
             assert False
 
-        assert props[INITIATOR_HANDLE] == self_handle
-        assert props[INITIATOR_ID] == self_name
-        assert CHANNEL_IFACE_GROUP in props[INTERFACES]
-        assert props[TARGET_ID] == 'chat2 at conf.localhost'
-        assert props[REQUESTED] == False
+        assert props[cs.INITIATOR_HANDLE] == self_handle
+        assert props[cs.INITIATOR_ID] == self_name
+        assert cs.CHANNEL_IFACE_GROUP in props[cs.INTERFACES]
+        assert props[cs.TARGET_ID] == 'chat2 at conf.localhost'
+        assert props[cs.REQUESTED] == False
 
     assert (got_text, got_tubes) == (True, True)
 
@@ -224,20 +224,20 @@ def test(q, bus, conn, stream):
     channels = event.args[0]
     assert len(channels) == 1
     path, prop = channels[0]
-    assert prop[CHANNEL_TYPE] == CHANNEL_TYPE_DBUS_TUBE
-    assert prop[INITIATOR_ID] == 'chat2 at conf.localhost/test'
-    assert prop[REQUESTED] == True
-    assert prop[TARGET_HANDLE_TYPE] == HT_ROOM
-    assert prop[TARGET_ID] == 'chat2 at conf.localhost'
-    assert prop[DBUS_TUBE_SERVICE_NAME] == 'com.example.TestCase'
+    assert prop[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE
+    assert prop[cs.INITIATOR_ID] == 'chat2 at conf.localhost/test'
+    assert prop[cs.REQUESTED] == True
+    assert prop[cs.TARGET_HANDLE_TYPE] == cs.HT_ROOM
+    assert prop[cs.TARGET_ID] == 'chat2 at conf.localhost'
+    assert prop[cs.DBUS_TUBE_SERVICE_NAME] == 'com.example.TestCase'
 
     tube_chan = bus.get_object(conn.bus_name, path)
-    dbus_tube_iface = dbus.Interface(tube_chan, CHANNEL_TYPE_DBUS_TUBE)
-    chan_iface = dbus.Interface(tube_chan, CHANNEL)
-    tube_props = tube_chan.GetAll(CHANNEL_IFACE_TUBE, dbus_interface=PROPERTIES_IFACE,
+    dbus_tube_iface = dbus.Interface(tube_chan, cs.CHANNEL_TYPE_DBUS_TUBE)
+    chan_iface = dbus.Interface(tube_chan, cs.CHANNEL)
+    tube_props = tube_chan.GetAll(cs.CHANNEL_IFACE_TUBE, dbus_interface=cs.PROPERTIES_IFACE,
         byte_arrays=True)
 
-    assert tube_props['State'] == TUBE_CHANNEL_STATE_NOT_OFFERED
+    assert tube_props['State'] == cs.TUBE_CHANNEL_STATE_NOT_OFFERED
 
     # offer the tube
     call_async(q, dbus_tube_iface, 'OfferDBusTube', sample_parameters)
@@ -246,18 +246,18 @@ def test(q, bus, conn, stream):
         EventPattern('dbus-signal', signal='NewTube'),
         EventPattern('stream-presence', to='chat2 at conf.localhost/test'),
         EventPattern('dbus-return', method='OfferDBusTube'),
-        EventPattern('dbus-signal', signal='TubeChannelStateChanged', args=[TUBE_CHANNEL_STATE_OPEN]),
-        EventPattern('dbus-signal', signal='DBusNamesChanged', interface=CHANNEL_TYPE_DBUS_TUBE))
+        EventPattern('dbus-signal', signal='TubeChannelStateChanged', args=[cs.TUBE_CHANNEL_STATE_OPEN]),
+        EventPattern('dbus-signal', signal='DBusNamesChanged', interface=cs.CHANNEL_TYPE_DBUS_TUBE))
 
-    tube_self_handle = tube_chan.GetSelfHandle(dbus_interface=CHANNEL_IFACE_GROUP)
+    tube_self_handle = tube_chan.GetSelfHandle(dbus_interface=cs.CHANNEL_IFACE_GROUP)
     assert tube_self_handle != 0
 
     # handle new_tube_event
     dbus_tube_id = new_tube_event.args[0]
-    assert new_tube_event.args[2] == TUBE_TYPE_DBUS
+    assert new_tube_event.args[2] == cs.TUBE_TYPE_DBUS
     assert new_tube_event.args[3] == 'com.example.TestCase'
     assert new_tube_event.args[4] == sample_parameters
-    assert new_tube_event.args[5] == TUBE_STATE_OPEN
+    assert new_tube_event.args[5] == cs.TUBE_STATE_OPEN
 
     # handle presence_event
     # We announce our newly created tube in our muc presence
@@ -272,7 +272,7 @@ def test(q, bus, conn, stream):
     dbus_tube_adr = return_event.value[0]
 
     bob_bus_name = ':2.Ym9i'
-    bob_handle = conn.RequestHandles(HT_CONTACT, ['chat2 at conf.localhost/bob'])[0]
+    bob_handle = conn.RequestHandles(cs.HT_CONTACT, ['chat2 at conf.localhost/bob'])[0]
 
     # Bob joins the tube
     presence = elem('presence', from_='chat2 at conf.localhost/bob', to='chat2 at conf.localhost')(
@@ -295,7 +295,7 @@ def test(q, bus, conn, stream):
     stream.send(presence)
 
     dbus_changed_event = q.expect('dbus-signal', signal='DBusNamesChanged',
-        interface=CHANNEL_TYPE_DBUS_TUBE)
+        interface=cs.CHANNEL_TYPE_DBUS_TUBE)
 
     added, removed = dbus_changed_event.args
     assert added == {bob_handle: bob_bus_name}
@@ -304,7 +304,7 @@ def test(q, bus, conn, stream):
     tube = Connection(dbus_tube_adr)
     fire_signal_on_tube(q, tube, 'chat2 at conf.localhost', dbus_stream_id, my_bus_name)
 
-    names = tube_chan.Get(CHANNEL_TYPE_DBUS_TUBE, 'DBusNames', dbus_interface=PROPERTIES_IFACE)
+    names = tube_chan.Get(cs.CHANNEL_TYPE_DBUS_TUBE, 'DBusNames', dbus_interface=cs.PROPERTIES_IFACE)
     assert names == {tube_self_handle: my_bus_name, bob_handle: bob_bus_name}
 
     # Bob leave the tube
@@ -314,13 +314,13 @@ def test(q, bus, conn, stream):
     stream.send(presence)
 
     dbus_changed_event = q.expect('dbus-signal', signal='DBusNamesChanged',
-        interface=CHANNEL_TYPE_DBUS_TUBE)
+        interface=cs.CHANNEL_TYPE_DBUS_TUBE)
 
     added, removed = dbus_changed_event.args
     assert added == {}
     assert removed == [bob_handle]
 
-    names = tube_chan.Get(CHANNEL_TYPE_DBUS_TUBE, 'DBusNames', dbus_interface=PROPERTIES_IFACE)
+    names = tube_chan.Get(cs.CHANNEL_TYPE_DBUS_TUBE, 'DBusNames', dbus_interface=cs.PROPERTIES_IFACE)
     assert names == {tube_self_handle: my_bus_name}
 
     chan_iface.Close()
diff --git a/tests/twisted/tubes/offer-muc-stream-tube.py b/tests/twisted/tubes/offer-muc-stream-tube.py
index 2d50365..fb562cd 100644
--- a/tests/twisted/tubes/offer-muc-stream-tube.py
+++ b/tests/twisted/tubes/offer-muc-stream-tube.py
@@ -6,7 +6,7 @@ import os
 import dbus
 
 from servicetest import call_async, EventPattern, EventProtocolFactory, unwrap
-from gabbletest import make_result_iq, acknowledge_iq, make_muc_presence
+from gabbletest import acknowledge_iq, make_muc_presence
 import constants as cs
 import ns
 import tubetestutil as t
diff --git a/tests/twisted/tubes/offer-private-stream-tube.py b/tests/twisted/tubes/offer-private-stream-tube.py
index 0e5f39f..7eba695 100644
--- a/tests/twisted/tubes/offer-private-stream-tube.py
+++ b/tests/twisted/tubes/offer-private-stream-tube.py
@@ -3,7 +3,7 @@
 import dbus
 
 from servicetest import call_async, EventPattern, sync_dbus
-from gabbletest import acknowledge_iq, sync_stream, exec_test
+from gabbletest import acknowledge_iq, sync_stream
 import constants as cs
 import ns
 import tubetestutil as t
diff --git a/tests/twisted/tubes/request-invalid-dbus-tube.py b/tests/twisted/tubes/request-invalid-dbus-tube.py
index fb84659..8a1cdad 100644
--- a/tests/twisted/tubes/request-invalid-dbus-tube.py
+++ b/tests/twisted/tubes/request-invalid-dbus-tube.py
@@ -1,7 +1,7 @@
 import dbus
 
 from gabbletest import exec_test
-from constants import *
+import constants as cs
 
 invalid_service_names = [ 'invalidServiceName'
                         , 'one ten hundred thousand million'
@@ -17,13 +17,13 @@ def test(q, bus, conn, stream):
     for invalid_service_name in invalid_service_names:
         try:
             conn.Requests.CreateChannel(
-                    {CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE,
-                     TARGET_HANDLE_TYPE: HT_CONTACT,
-                     TARGET_ID: 'alice at localhost',
-                     DBUS_TUBE_SERVICE_NAME: invalid_service_name
+                    {cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
+                     cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+                     cs.TARGET_ID: 'alice at localhost',
+                     cs.DBUS_TUBE_SERVICE_NAME: invalid_service_name
                 });
         except dbus.DBusException, e:
-            assert e.get_dbus_name() == INVALID_ARGUMENT, \
+            assert e.get_dbus_name() == cs.INVALID_ARGUMENT, \
                 (e.get_dbus_name(), invalid_service_name)
         else:
             assert False
diff --git a/tests/twisted/tubes/test-get-available-tubes.py b/tests/twisted/tubes/test-get-available-tubes.py
index 8dc9c9c..d53d27c 100644
--- a/tests/twisted/tubes/test-get-available-tubes.py
+++ b/tests/twisted/tubes/test-get-available-tubes.py
@@ -3,10 +3,8 @@
 import dbus
 
 from servicetest import call_async, EventPattern, tp_name_prefix
-from gabbletest import exec_test, make_result_iq, acknowledge_iq, make_muc_presence
-import ns
-
-from twisted.words.xish import domish
+from gabbletest import (
+    exec_test, make_result_iq, acknowledge_iq, make_muc_presence)
 
 sample_parameters = dbus.Dictionary({
     's': 'hello',
diff --git a/tests/twisted/tubes/tubetestutil.py b/tests/twisted/tubes/tubetestutil.py
index 1e870f5..570ff8a 100644
--- a/tests/twisted/tubes/tubetestutil.py
+++ b/tests/twisted/tubes/tubetestutil.py
@@ -6,13 +6,11 @@ import errno
 import os
 
 import dbus
-from dbus import PROPERTIES_IFACE
 
 from servicetest import unwrap
 from gabbletest import exec_test
-from constants import *
-from bytestream import BytestreamIBBMsg, BytestreamS5B, BytestreamSIFallbackS5CannotConnect,\
-    BytestreamSIFallbackS5WrongHash, BytestreamIBBIQ, BytestreamS5BRelay, BytestreamS5BRelayBugged
+import constants as cs
+import bytestream
 
 from twisted.internet import reactor
 from twisted.internet.protocol import Factory, Protocol
@@ -56,8 +54,8 @@ def check_conn_properties(q, conn, channel_list=None):
     """
 
     properties = conn.GetAll(
-            CONN_IFACE_REQUESTS,
-            dbus_interface=PROPERTIES_IFACE)
+            cs.CONN_IFACE_REQUESTS,
+            dbus_interface=cs.PROPERTIES_IFACE)
 
     if channel_list == None:
         assert properties.get('Channels') == [], properties['Channels']
@@ -67,50 +65,50 @@ def check_conn_properties(q, conn, channel_list=None):
                 (i, properties['Channels'])
 
     # 1-1 tubes channel (old API)
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_TUBES,
-             TARGET_HANDLE_TYPE: HT_CONTACT,
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TUBES,
+             cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
              },
-             [TARGET_HANDLE, TARGET_ID
+             [cs.TARGET_HANDLE, cs.TARGET_ID
              ]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
     # muc tubes channel (old API)
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_TUBES,
-             TARGET_HANDLE_TYPE: HT_ROOM,
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TUBES,
+             cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
              },
-             [TARGET_HANDLE, TARGET_ID
+             [cs.TARGET_HANDLE, cs.TARGET_ID
              ]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
     # 1-1 StreamTube channel
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
-             TARGET_HANDLE_TYPE: HT_CONTACT
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAM_TUBE,
+             cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT
              },
-             [TARGET_HANDLE, TARGET_ID, STREAM_TUBE_SERVICE]
+             [cs.TARGET_HANDLE, cs.TARGET_ID, cs.STREAM_TUBE_SERVICE]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
     # muc StreamTube channel
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
-             TARGET_HANDLE_TYPE: HT_ROOM
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAM_TUBE,
+             cs.TARGET_HANDLE_TYPE: cs.HT_ROOM
              },
-             [TARGET_HANDLE, TARGET_ID, STREAM_TUBE_SERVICE]
+             [cs.TARGET_HANDLE, cs.TARGET_ID, cs.STREAM_TUBE_SERVICE]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
     # 1-1 D-Bus tube channel
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE,
-            TARGET_HANDLE_TYPE: HT_CONTACT},
-             [TARGET_HANDLE, TARGET_ID, DBUS_TUBE_SERVICE_NAME]
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
+            cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT},
+             [cs.TARGET_HANDLE, cs.TARGET_ID, cs.DBUS_TUBE_SERVICE_NAME]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
     # muc D-Bus tube channel
-    assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE,
-            TARGET_HANDLE_TYPE: HT_ROOM},
-             [TARGET_HANDLE, TARGET_ID, DBUS_TUBE_SERVICE_NAME]
+    assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
+            cs.TARGET_HANDLE_TYPE: cs.HT_ROOM},
+             [cs.TARGET_HANDLE, cs.TARGET_ID, cs.DBUS_TUBE_SERVICE_NAME]
             ) in properties.get('RequestableChannelClasses'),\
                      properties['RequestableChannelClasses']
 
@@ -124,7 +122,7 @@ def check_NewChannel_signal(args, channel_type, chan_path, contact_handle,
     if chan_path is not None:
         assert args[0] == chan_path, (args, chan_path)
     assert args[1] == channel_type, (args, channel_type)
-    assert args[2] == HT_CONTACT, (args, HT_CONTACT)
+    assert args[2] == cs.HT_CONTACT, (args, cs.HT_CONTACT)
     assert args[3] == contact_handle, (args, contact_handle)
     assert args[4] == suppress_handler, (args, suppress_handler)
 
@@ -140,14 +138,14 @@ def check_NewChannels_signal(args, channel_type, chan_path, contact_handle,
 
     assert path == chan_path, (emitted_path, chan_path)
 
-    assert props[CHANNEL_TYPE] == channel_type, (props, channel_type)
-    assert props[TARGET_HANDLE_TYPE] == HT_CONTACT, props
-    assert props[TARGET_HANDLE] == contact_handle, (props, contact_handle)
-    assert props[TARGET_ID] == contact_id, (props, contact_id)
-    assert props[REQUESTED] == True, props
-    assert props[INITIATOR_HANDLE] == initiator_handle, \
+    assert props[cs.CHANNEL_TYPE] == channel_type, (props, channel_type)
+    assert props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT, props
+    assert props[cs.TARGET_HANDLE] == contact_handle, (props, contact_handle)
+    assert props[cs.TARGET_ID] == contact_id, (props, contact_id)
+    assert props[cs.REQUESTED] == True, props
+    assert props[cs.INITIATOR_HANDLE] == initiator_handle, \
         (props, initiator_handle)
-    assert props[INITIATOR_ID] == 'test at localhost', props
+    assert props[cs.INITIATOR_ID] == 'test at localhost', props
 
 def check_channel_properties(q, bus, conn, channel, channel_type,
                              contact_handle, contact_id, state=None):
@@ -157,15 +155,15 @@ def check_channel_properties(q, bus, conn, channel, channel_type,
     """
 
     # Check o.fd.T.Channel properties.
-    channel_props = channel.GetAll(CHANNEL, dbus_interface=PROPERTIES_IFACE)
+    channel_props = channel.GetAll(cs.CHANNEL, dbus_interface=cs.PROPERTIES_IFACE)
     assert channel_props.get('TargetHandle') == contact_handle, \
             (channel_props.get('TargetHandle'), contact_handle)
-    assert channel_props.get('TargetHandleType') == HT_CONTACT, \
+    assert channel_props.get('TargetHandleType') == cs.HT_CONTACT, \
             channel_props.get('TargetHandleType')
     assert channel_props.get('ChannelType') == channel_type, \
             channel_props.get('ChannelType')
     assert 'Interfaces' in channel_props, channel_props
-    assert CHANNEL_IFACE_GROUP not in \
+    assert cs.CHANNEL_IFACE_GROUP not in \
             channel_props['Interfaces'], \
             channel_props['Interfaces']
     assert channel_props['TargetID'] == contact_id
@@ -173,24 +171,24 @@ def check_channel_properties(q, bus, conn, channel, channel_type,
     assert channel_props['InitiatorID'] == 'test at localhost'
     assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
 
-    if channel_type == CHANNEL_TYPE_TUBES:
+    if channel_type == cs.CHANNEL_TYPE_TUBES:
         assert state is None
         assert len(channel_props['Interfaces']) == 0, channel_props['Interfaces']
         supported_socket_types = channel.GetAvailableStreamTubeTypes()
     else:
         assert state is not None
-        tube_props = channel.GetAll(CHANNEL_IFACE_TUBE,
-                dbus_interface=PROPERTIES_IFACE)
+        tube_props = channel.GetAll(cs.CHANNEL_IFACE_TUBE,
+                dbus_interface=cs.PROPERTIES_IFACE)
         assert tube_props['State'] == state
         # no strict check but at least check the properties exist
         assert tube_props['Parameters'] is not None
         assert channel_props['Interfaces'] == \
-            dbus.Array([CHANNEL_IFACE_TUBE], signature='s'), \
+            dbus.Array([cs.CHANNEL_IFACE_TUBE], signature='s'), \
             channel_props['Interfaces']
 
-        if channel_type == CHANNEL_TYPE_STREAM_TUBE:
-            supported_socket_types = channel.Get(CHANNEL_TYPE_STREAM_TUBE,
-                'SupportedSocketTypes', dbus_interface=PROPERTIES_IFACE)
+        if channel_type == cs.CHANNEL_TYPE_STREAM_TUBE:
+            supported_socket_types = channel.Get(cs.CHANNEL_TYPE_STREAM_TUBE,
+                'SupportedSocketTypes', dbus_interface=cs.PROPERTIES_IFACE)
         else:
             supported_socket_types = None
 
@@ -221,6 +219,14 @@ def set_up_echo(name):
     return full_path
 
 def exec_tube_test(test):
-    for bytestream_cls in [BytestreamIBBMsg, BytestreamIBBIQ, BytestreamS5B, BytestreamSIFallbackS5CannotConnect,
-            BytestreamSIFallbackS5WrongHash, BytestreamS5BRelay, BytestreamS5BRelayBugged]:
-        exec_test(lambda q, bus, conn, stream: test(q, bus, conn, stream, bytestream_cls))
+    for bytestream_cls in [
+            bytestream.BytestreamIBBMsg,
+            bytestream.BytestreamIBBIQ,
+            bytestream.BytestreamS5B,
+            bytestream.BytestreamSIFallbackS5CannotConnect,
+            bytestream.BytestreamSIFallbackS5WrongHash,
+            bytestream.BytestreamS5BRelay,
+            bytestream.BytestreamS5BRelayBugged]:
+        exec_test(lambda q, bus, conn, stream:
+            test(q, bus, conn, stream, bytestream_cls))
+
diff --git a/tests/twisted/vcard/test-avatar-retrieved.py b/tests/twisted/vcard/test-avatar-retrieved.py
index 065637e..c77c7bb 100644
--- a/tests/twisted/vcard/test-avatar-retrieved.py
+++ b/tests/twisted/vcard/test-avatar-retrieved.py
@@ -5,7 +5,6 @@ RequestAvatar calls for the same contact.
 """
 
 import base64
-import sha
 
 from servicetest import EventPattern
 from gabbletest import exec_test, acknowledge_iq
diff --git a/tests/twisted/vcard/test-save-alias-to-vcard.py b/tests/twisted/vcard/test-save-alias-to-vcard.py
index 4ff2ee3..9b5af31 100644
--- a/tests/twisted/vcard/test-save-alias-to-vcard.py
+++ b/tests/twisted/vcard/test-save-alias-to-vcard.py
@@ -7,10 +7,8 @@ Regression test.
    parameter
 """
 
-from gabbletest import exec_test, acknowledge_iq, \
-    expect_and_handle_get_vcard, expect_and_handle_set_vcard
-
-import ns
+from gabbletest import (
+    exec_test, expect_and_handle_get_vcard, expect_and_handle_set_vcard)
 
 def test(q, bus, conn, stream):
     conn.Connect()
diff --git a/tests/twisted/vcard/test-vcard-race.py b/tests/twisted/vcard/test-vcard-race.py
index ba2726c..0bc85db 100644
--- a/tests/twisted/vcard/test-vcard-race.py
+++ b/tests/twisted/vcard/test-vcard-race.py
@@ -13,11 +13,9 @@ import base64
 
 from twisted.words.xish import xpath
 
-from servicetest import call_async, sync_dbus
-from gabbletest import exec_test, \
-    expect_and_handle_get_vcard, expect_and_handle_set_vcard
-
-import ns
+from servicetest import call_async
+from gabbletest import (
+    exec_test, expect_and_handle_get_vcard, expect_and_handle_set_vcard)
 
 def test(q, bus, conn, stream):
     conn.Connect()
-- 
1.5.6.5




More information about the telepathy-commits mailing list