[telepathy-gabble/master] use disconnect_conn in tests

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Tue Jul 14 05:47:02 PDT 2009


---
 tests/twisted/connect/test-twice.py                |   20 +++---------------
 tests/twisted/jingle/google-relay.py               |    9 ++-----
 .../jingle/test-wait-for-caps-incomplete.py        |   13 +++--------
 tests/twisted/muc/roomlist.py                      |   21 +++++++------------
 tests/twisted/olpc/gadget-invite.py                |    7 +----
 tests/twisted/tubes/accept-muc-stream-tube.py      |    9 ++-----
 6 files changed, 24 insertions(+), 55 deletions(-)

diff --git a/tests/twisted/connect/test-twice.py b/tests/twisted/connect/test-twice.py
index a2a47a4..3d28ab9 100644
--- a/tests/twisted/connect/test-twice.py
+++ b/tests/twisted/connect/test-twice.py
@@ -11,7 +11,7 @@ import servicetest
 
 from gabbletest import (
     make_connection, make_stream, JabberAuthenticator, XmppAuthenticator,
-    XmppXmlStream, JabberXmlStream)
+    XmppXmlStream, JabberXmlStream, disconnect_conn)
 
 def test(q, bus, conn1, conn2, stream1, stream2):
     # Connection 1
@@ -31,14 +31,10 @@ def test(q, bus, conn1, conn2, stream1, stream2):
     q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
 
     # Disconnection 1
-    conn1.Disconnect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+    disconnect_conn(q, conn1, stream1)
 
     # Disconnection 2
-    conn2.Disconnect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-    return True
+    disconnect_conn(q, conn2, stream2)
 
 if __name__ == '__main__':
     queue = servicetest.IteratingEventQueue(None)
@@ -74,12 +70,4 @@ if __name__ == '__main__':
     stream2 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
                           port=4343)
 
-    try:
-        test(queue, bus, conn1, conn2, stream1, stream2)
-    finally:
-        try:
-            conn1.Disconnect()
-            conn2.Disconnect()
-        except dbus.DBusException, e:
-            pass
-
+    test(queue, bus, conn1, conn2, stream1, stream2)
diff --git a/tests/twisted/jingle/google-relay.py b/tests/twisted/jingle/google-relay.py
index 1d00531..673c185 100644
--- a/tests/twisted/jingle/google-relay.py
+++ b/tests/twisted/jingle/google-relay.py
@@ -3,7 +3,7 @@ Test getting relay from Google jingleinfo
 """
 
 from gabbletest import exec_test, make_result_iq, sync_stream, \
-        GoogleXmlStream
+        GoogleXmlStream, disconnect_conn
 from servicetest import make_channel_proxy, tp_path_prefix, \
         EventPattern, call_async, sync_dbus
 import jingletest
@@ -306,7 +306,8 @@ def test_too_slow(q, bus, conn, stream, httpd, media_chan, too_slow):
         media_chan.RemoveMembers([conn.GetSelfHandle()], "",
             dbus_interface=cs.CHANNEL_IFACE_GROUP)
     elif too_slow == TOO_SLOW_DISCONNECT:
-        conn.Disconnect()
+        disconnect_conn(q, conn, stream)
+        return
 
     q.expect('dbus-signal', signal='Closed',
         path=media_chan.object_path[len(tp_path_prefix):])
@@ -323,10 +324,6 @@ def test_too_slow(q, bus, conn, stream, httpd, media_chan, too_slow):
         # Make a misc method call to check that Gabble's still alive.
         sync_dbus(bus, q, conn)
 
-        conn.Disconnect()
-        q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-
 if __name__ == '__main__':
     exec_test(lambda q, b, c, s: test(q, b, c, s, incoming=True),
             protocol=GoogleXmlStream)
diff --git a/tests/twisted/jingle/test-wait-for-caps-incomplete.py b/tests/twisted/jingle/test-wait-for-caps-incomplete.py
index e8eeb8b..f5f677f 100644
--- a/tests/twisted/jingle/test-wait-for-caps-incomplete.py
+++ b/tests/twisted/jingle/test-wait-for-caps-incomplete.py
@@ -4,8 +4,8 @@ and returns an error when Disconnect is called and there are
 incomplete requests.
 """
 
-from gabbletest import exec_test
-from servicetest import make_channel_proxy, call_async, sync_dbus
+from gabbletest import exec_test, disconnect_conn
+from servicetest import make_channel_proxy, call_async, sync_dbus, EventPattern
 import jingletest
 
 import constants as cs
@@ -44,17 +44,12 @@ def test(q, bus, conn, stream):
     call_async(q, media_iface, 'RequestStreams', handle,
         [cs.MEDIA_STREAM_TYPE_AUDIO])
 
-    conn.Disconnect()
+    event = disconnect_conn(q, conn, stream,
+        [EventPattern('dbus-error', method='RequestStreams')])[0]
 
     # RequestStreams should now return NotAvailable
-    event = q.expect('dbus-error', method='RequestStreams')
     assert event.error.get_dbus_name() == cs.NOT_AVAILABLE, event.error
 
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-    return True
-
-
 if __name__ == '__main__':
     exec_test(test, timeout=10)
 
diff --git a/tests/twisted/muc/roomlist.py b/tests/twisted/muc/roomlist.py
index ce0bdd4..2bcc21b 100644
--- a/tests/twisted/muc/roomlist.py
+++ b/tests/twisted/muc/roomlist.py
@@ -5,7 +5,7 @@ Test MUC support.
 
 import dbus
 
-from gabbletest import make_result_iq, exec_test, sync_stream
+from gabbletest import make_result_iq, exec_test, sync_stream, disconnect_conn
 from servicetest import call_async, EventPattern, \
         tp_name_prefix, tp_path_prefix
 
@@ -167,18 +167,13 @@ def test(q, bus, conn, stream):
     assert not yours
     assert ensured_path == path2, (ensured_path, path2)
 
-
-    conn.Disconnect()
-
-    q.expect_many(
-            EventPattern('dbus-signal', signal='Closed',
-                path=path1[len(tp_path_prefix):]),
-            EventPattern('dbus-signal', signal='Closed',
-                path=path2[len(tp_path_prefix):]),
-            EventPattern('dbus-signal', signal='ChannelClosed', args=[path1]),
-            EventPattern('dbus-signal', signal='ChannelClosed', args=[path2]),
-            EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]),
-            )
+    disconnect_conn(q, conn, stream, [
+    EventPattern('dbus-signal', signal='Closed',
+        path=path1[len(tp_path_prefix):]),
+    EventPattern('dbus-signal', signal='Closed',
+        path=path2[len(tp_path_prefix):]),
+    EventPattern('dbus-signal', signal='ChannelClosed', args=[path1]),
+    EventPattern('dbus-signal', signal='ChannelClosed', args=[path2])])
 
 if __name__ == '__main__':
     exec_test(test)
diff --git a/tests/twisted/olpc/gadget-invite.py b/tests/twisted/olpc/gadget-invite.py
index db54ebf..d608161 100644
--- a/tests/twisted/olpc/gadget-invite.py
+++ b/tests/twisted/olpc/gadget-invite.py
@@ -6,7 +6,7 @@ import dbus
 
 from servicetest import call_async, EventPattern
 from gabbletest import exec_test, make_result_iq, acknowledge_iq, sync_stream,\
-    make_muc_presence
+    make_muc_presence, disconnect_conn
 import constants as cs
 
 from twisted.words.xish import xpath
@@ -121,11 +121,8 @@ def test(q, bus, conn, stream):
     presence = simple_presence_iface.GetPresences([handle])
     assert presence[handle] == (7, 'unknown', '')
 
-    conn.Disconnect()
-
     # PEP activity update
-    event = q.expect('stream-iq')
-    acknowledge_iq(stream, event.stanza)
+    disconnect_conn(q, conn, stream, [EventPattern('stream-iq')])[0]
 
 if __name__ == '__main__':
     exec_test(test)
diff --git a/tests/twisted/tubes/accept-muc-stream-tube.py b/tests/twisted/tubes/accept-muc-stream-tube.py
index fe10bb2..339aa71 100644
--- a/tests/twisted/tubes/accept-muc-stream-tube.py
+++ b/tests/twisted/tubes/accept-muc-stream-tube.py
@@ -3,7 +3,7 @@
 import dbus
 
 from servicetest import call_async, EventPattern, EventProtocolClientFactory, unwrap, assertEquals
-from gabbletest import make_result_iq, acknowledge_iq, make_muc_presence, send_error_reply
+from gabbletest import make_result_iq, acknowledge_iq, make_muc_presence, send_error_reply, disconnect_conn
 import constants as cs
 import ns
 import tubetestutil as t
@@ -262,11 +262,8 @@ def test(q, bus, conn, stream, bytestream_cls,
     assertEquals(cs.CANCELLED, e.args[1])
 
     # OK, we're done
-    conn.Disconnect()
-
-    q.expect_many(
-        EventPattern('dbus-signal', signal='TubeClosed', args=[stream_tube_id]),
-        EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]))
+    disconnect_conn(q, conn, stream,
+        [EventPattern('dbus-signal', signal='TubeClosed', args=[stream_tube_id])])
 
 if __name__ == '__main__':
     t.exec_stream_tube_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list