[telepathy-gabble/telepathy-gabble-0.8] expect_many(): ignore patterns that have already matched

Dafydd Harries dafydd.harries at collabora.co.uk
Mon Sep 21 06:47:34 PDT 2009


---
 tests/twisted/servicetest.py |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/tests/twisted/servicetest.py b/tests/twisted/servicetest.py
index 1137c3f..4b2ccb9 100644
--- a/tests/twisted/servicetest.py
+++ b/tests/twisted/servicetest.py
@@ -142,7 +142,7 @@ class BaseEventQueue:
             self._check_forbidden(event)
 
             for i, pattern in enumerate(patterns):
-                if pattern.match(event):
+                if ret[i] is None and pattern.match(event):
                     self.log('handled')
                     self.log('')
                     ret[i] = event
@@ -222,6 +222,16 @@ class EventQueueTest(unittest.TestCase):
         assert bar.type == 'bar'
         assert foo.type == 'foo'
 
+    def test_expect_many2(self):
+        # Test that events are only matched against patterns that haven't yet
+        # been matched. This tests a regression.
+        queue = TestEventQueue([Event('foo', x=1), Event('foo', x=2)])
+        foo1, foo2 = queue.expect_many(
+            EventPattern('foo'),
+            EventPattern('foo'))
+        assert foo1.type == 'foo' and foo1.x == 1
+        assert foo2.type == 'foo' and foo2.x == 2
+
     def test_timeout(self):
         queue = TestEventQueue([])
         self.assertRaises(TimeoutError, queue.expect, 'foo')
-- 
1.5.6.5




More information about the telepathy-commits mailing list