[telepathy-gabble/master] Refactor self-caps tests to give better output on failure

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Jul 28 14:52:38 PDT 2009


---
 tests/twisted/caps/advertise-draft1.py |   33 +++++++++++++++----------------
 tests/twisted/caps/advertise-legacy.py |   28 +++++++++++++-------------
 tests/twisted/caps/tube-caps.py        |   11 +++++----
 tests/twisted/caps_helper.py           |   31 ++++++++++++++++++-----------
 4 files changed, 55 insertions(+), 48 deletions(-)

diff --git a/tests/twisted/caps/advertise-draft1.py b/tests/twisted/caps/advertise-draft1.py
index c4f4c16..656e210 100644
--- a/tests/twisted/caps/advertise-draft1.py
+++ b/tests/twisted/caps/advertise-draft1.py
@@ -37,9 +37,9 @@ def run_test(q, bus, conn, stream):
             (cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, JINGLE_CAPS)
+    check_caps(namespaces, JINGLE_CAPS)
     # Immediately afterwards, we get SetSelfCapabilities, for which a
     # more comprehensive test exists in tube-caps.py.
     conn.ContactCapabilities.SetSelfCapabilities([
@@ -51,19 +51,18 @@ def run_test(q, bus, conn, stream):
             cs.STREAM_TUBE_SERVICE: 'x-abiword' },
         { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA },
         ])
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
-            JINGLE_CAPS + [ns.TUBES + '/stream#x-abiword'])
+    check_caps(namespaces, JINGLE_CAPS + [ns.TUBES + '/stream#x-abiword'])
 
     # Remove all our caps again
     add = []
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
     # the call to SSC has no effect here
     conn.ContactCapabilities.SetSelfCapabilities([])
     noop_presence_update(q, stream)
@@ -78,9 +77,9 @@ def run_test(q, bus, conn, stream):
         cs.MEDIA_CAP_AUDIO | cs.MEDIA_CAP_GTALKP2P)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.GOOGLE_P2P, ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.GOOGLE_FEAT_VOICE, ns.JINGLE_RTP_AUDIO,
                 ns.JINGLE_RTP, ns.JINGLE_015_AUDIO])
@@ -95,9 +94,9 @@ def run_test(q, bus, conn, stream):
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
     # the call to SSC has no effect here
     conn.ContactCapabilities.SetSelfCapabilities([])
     noop_presence_update(q, stream)
@@ -107,9 +106,9 @@ def run_test(q, bus, conn, stream):
     add = [(cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.MEDIA_CAP_AUDIO)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.JINGLE_RTP_AUDIO,
                 ns.JINGLE_RTP, ns.JINGLE_015_AUDIO])
@@ -124,9 +123,9 @@ def run_test(q, bus, conn, stream):
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
     # the call to SSC has no effect here
     conn.ContactCapabilities.SetSelfCapabilities([])
     noop_presence_update(q, stream)
@@ -137,9 +136,9 @@ def run_test(q, bus, conn, stream):
         cs.MEDIA_CAP_VIDEO | cs.MEDIA_CAP_ICEUDP)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.JINGLE_TRANSPORT_ICEUDP, ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.JINGLE_RTP_VIDEO,
                 ns.JINGLE_RTP, ns.JINGLE_015_VIDEO])
diff --git a/tests/twisted/caps/advertise-legacy.py b/tests/twisted/caps/advertise-legacy.py
index 3910567..5b577f8 100644
--- a/tests/twisted/caps/advertise-legacy.py
+++ b/tests/twisted/caps/advertise-legacy.py
@@ -32,18 +32,18 @@ def run_test(q, bus, conn, stream):
             (cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, JINGLE_CAPS)
+    check_caps(namespaces, JINGLE_CAPS)
 
     # Remove all our caps again
     add = []
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
 
     # Add caps selectively (i.e. what a client that actually understood the
     # old Capabilities interface would do). With AUDIO and GTALK_P2P, we're
@@ -55,9 +55,9 @@ def run_test(q, bus, conn, stream):
         cs.MEDIA_CAP_AUDIO | cs.MEDIA_CAP_GTALKP2P)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.GOOGLE_P2P, ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.GOOGLE_FEAT_VOICE, ns.JINGLE_RTP_AUDIO,
                 ns.JINGLE_RTP, ns.JINGLE_015_AUDIO])
@@ -67,18 +67,18 @@ def run_test(q, bus, conn, stream):
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
 
     # With AUDIO but no transport, we are only callable via raw UDP, which
     # Google clients cannot do.
     add = [(cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.MEDIA_CAP_AUDIO)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.JINGLE_RTP_AUDIO,
                 ns.JINGLE_RTP, ns.JINGLE_015_AUDIO])
@@ -88,9 +88,9 @@ def run_test(q, bus, conn, stream):
     remove = [cs.CHANNEL_TYPE_STREAMED_MEDIA,
             cs.CHANNEL_TYPE_STREAM_TUBE]
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str, [])
+    check_caps(namespaces, [])
 
     # With VIDEO and ICE-UDP only, we are very futuristic indeed.
     # Google clients cannot interop with us.
@@ -98,9 +98,9 @@ def run_test(q, bus, conn, stream):
         cs.MEDIA_CAP_VIDEO | cs.MEDIA_CAP_ICEUDP)]
     remove = []
     caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
-    (disco_response, caps_str, _) = receive_presence_and_ask_caps(q, stream,
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
             False)
-    check_caps(disco_response, caps_str,
+    check_caps(namespaces,
             [ns.JINGLE_TRANSPORT_ICEUDP, ns.JINGLE_TRANSPORT_RAWUDP, ns.JINGLE,
                 ns.JINGLE_015, ns.JINGLE_RTP_VIDEO,
                 ns.JINGLE_RTP, ns.JINGLE_015_VIDEO])
diff --git a/tests/twisted/caps/tube-caps.py b/tests/twisted/caps/tube-caps.py
index 3b41d16..33a4a6d 100644
--- a/tests/twisted/caps/tube-caps.py
+++ b/tests/twisted/caps/tube-caps.py
@@ -35,7 +35,8 @@ import dbus
 
 from twisted.words.xish import xpath
 
-from servicetest import assertEquals, assertLength
+from servicetest import assertEquals, assertLength, assertContains,\
+        assertDoesNotContain
 from gabbletest import exec_test, make_result_iq, sync_stream, make_presence
 import constants as cs
 
@@ -205,17 +206,17 @@ def advertise_caps(q, conn, stream, filters, expected_features, unexpected_featu
     ret_caps = conn.ContactCapabilities.SetSelfCapabilities(filters)
 
     # Expect Gabble to reply with the correct caps
-    event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, stream)
+    event, namespaces, signaled_caps = receive_presence_and_ask_caps(q, stream)
 
     assertSameElements(expected_caps, signaled_caps)
 
-    assert caps_contain(event, ns.TUBES) == True, caps_str
+    assertContains(ns.TUBES, namespaces)
 
     for var in expected_features:
-        assert caps_contain(event, var), (var, caps_str)
+        assertContains(var, namespaces)
 
     for var in unexpected_features:
-        assert not caps_contain(event, var), (var, caps_str)
+        assertDoesNotContain(var, namespaces)
 
     # Check our own caps
     caps = conn.ContactCapabilities.GetContactCapabilities([self_handle])
diff --git a/tests/twisted/caps_helper.py b/tests/twisted/caps_helper.py
index 508c467..1a2c83b 100644
--- a/tests/twisted/caps_helper.py
+++ b/tests/twisted/caps_helper.py
@@ -5,7 +5,8 @@ import dbus
 
 from twisted.words.xish import domish, xpath
 from gabbletest import make_result_iq
-from servicetest import EventPattern, assertEquals
+from servicetest import EventPattern, assertEquals, assertContains, \
+        assertDoesNotContain
 
 from config import PACKAGE_STRING
 import ns
@@ -48,24 +49,28 @@ VARIABLE_CAPS = (
     # ns.FILE_TRANSFER,
     # ns.TUBES,
 
-    # there is an unlimited set of these; only the one actually relevant to
-    # my tests is shown here
+    # there is an unlimited set of these; only the ones actually relevant to
+    # the tests so far are shown here
     ns.TUBES + '/stream#x-abiword',
+    ns.TUBES + '/stream#daap',
+    ns.TUBES + '/stream#http',
+    ns.TUBES + '/dbus#com.example.Go',
+    ns.TUBES + '/dbus#com.example.Xiangqi',
     ])
 
-def check_caps(disco_response, caps_str, desired):
+def check_caps(namespaces, desired):
     """Assert that all the FIXED_CAPS are supported, and of the VARIABLE_CAPS,
     every capability in desired is supported, and every other capability is
     not.
     """
     for c in FIXED_CAPS:
-        assert caps_contain(disco_response, c), (c, caps_str)
+        assertContains(c, namespaces)
 
     for c in VARIABLE_CAPS:
         if c in desired:
-            assert caps_contain(disco_response, c), (c, caps_str)
+            assertContains(c, namespaces)
         else:
-            assert not caps_contain(disco_response, c), (c, caps_str)
+            assertDoesNotContain(c, namespaces)
 
 text_fixed_properties = dbus.Dictionary({
     cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
@@ -172,17 +177,20 @@ def make_caps_disco_reply(stream, req, features, dataforms={}):
 def receive_presence_and_ask_caps(q, stream, expect_dbus=True):
     # receive presence stanza
     if expect_dbus:
-        event_stream, event_dbus = q.expect_many(
+        presence, event_dbus = q.expect_many(
                 EventPattern('stream-presence'),
                 EventPattern('dbus-signal', signal='ContactCapabilitiesChanged')
             )
         assert len(event_dbus.args) == 1
         signaled_caps = event_dbus.args[0]
     else:
-        event_stream = q.expect('stream-presence')
+        presence = q.expect('stream-presence')
         signaled_caps = None
 
-    c_nodes = xpath.queryForNodes('/presence/c', event_stream.stanza)
+    return disco_caps(q, stream, presence) + (signaled_caps,)
+
+def disco_caps(q, stream, presence):
+    c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
     assert c_nodes is not None
     assert len(c_nodes) == 1
     hash = c_nodes[0].attributes['hash']
@@ -204,7 +212,6 @@ def receive_presence_and_ask_caps(q, stream, expect_dbus=True):
 
     # receive caps
     event = q.expect('stream-iq', query_ns=ns.DISCO_INFO)
-    caps_str = str(xpath.queryForNodes('/iq/query/feature', event.stanza))
 
     features = []
     for feature in xpath.queryForNodes('/iq/query/feature', event.stanza):
@@ -213,7 +220,7 @@ def receive_presence_and_ask_caps(q, stream, expect_dbus=True):
     # Check if the hash matches the announced capabilities
     assert ver == compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], features, {})
 
-    return (event, caps_str, signaled_caps)
+    return (event, features)
 
 def caps_contain(event, cap):
     node = xpath.queryForNodes('/iq/query/feature[@var="%s"]'
-- 
1.5.6.5




More information about the telepathy-commits mailing list