[Telepathy-commits] [telepathy-salut/master] Add hook functions to the iterating queue to inspect events

Sjoerd Simons sjoerd.simons at collabora.co.uk
Mon Sep 15 04:07:42 PDT 2008


---
 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 4a56f90..004e52b 100644
--- a/tests/twisted/servicetest.py
+++ b/tests/twisted/servicetest.py
@@ -197,6 +197,7 @@ class BaseEventQueue:
 
     Implement the wait() method to have something that works.
     """
+    hooks = []
 
     def __init__(self, timeout=None):
         self.verbose = False
@@ -210,6 +211,13 @@ class BaseEventQueue:
         if self.verbose:
             print s
 
+    def hook(self, func, type, **kw):
+        self.hooks.append( (EventPattern(type, **kw), func))
+
+    def check_hooks(self, event):
+        map (lambda x: x[1](self, event),
+            filter (lambda x: x[0].match(event), self.hooks))
+
     def expect(self, type, **kw):
         pattern = EventPattern(type, **kw)
 
@@ -281,7 +289,9 @@ class IteratingEventQueue(BaseEventQueue):
 
         if self.events:
             delayed_call.cancel()
-            return self.events.pop(0)
+            e = self.events.pop(0)
+            self.check_hooks(e)
+            return e
         else:
             raise TimeoutError
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list