[py-svn] r51123 - in py/branch/event/py/event: . testing

hpk at codespeak.net hpk at codespeak.net
Wed Jan 30 13:00:35 CET 2008


Author: hpk
Date: Wed Jan 30 13:00:34 2008
New Revision: 51123

Added:
   py/branch/event/py/event/__init__.py   (contents, props changed)
   py/branch/event/py/event/hub.py   (contents, props changed)
   py/branch/event/py/event/testing/__init__.py   (contents, props changed)
   py/branch/event/py/event/testing/test_hub.py   (contents, props changed)
Modified:
   py/branch/event/py/event/   (props changed)
   py/branch/event/py/event/testing/   (props changed)
Log:
actually adding the code for the event hub. 


Added: py/branch/event/py/event/__init__.py
==============================================================================
--- (empty file)
+++ py/branch/event/py/event/__init__.py	Wed Jan 30 13:00:34 2008
@@ -0,0 +1 @@
+#

Added: py/branch/event/py/event/hub.py
==============================================================================
--- (empty file)
+++ py/branch/event/py/event/hub.py	Wed Jan 30 13:00:34 2008
@@ -0,0 +1,6 @@
+
+class Hub(list):
+    """ General Event Hub """ 
+    def notify(self, event):
+        for subscriber in self:
+            subscriber(event) 

Added: py/branch/event/py/event/testing/__init__.py
==============================================================================
--- (empty file)
+++ py/branch/event/py/event/testing/__init__.py	Wed Jan 30 13:00:34 2008
@@ -0,0 +1 @@
+#

Added: py/branch/event/py/event/testing/test_hub.py
==============================================================================
--- (empty file)
+++ py/branch/event/py/event/testing/test_hub.py	Wed Jan 30 13:00:34 2008
@@ -0,0 +1,33 @@
+import py
+
+class TestHub:
+
+    def test_simple(self):
+        hub = py.event.Hub()
+        l = []
+        hub.append(l.append) 
+        hub.notify(1)
+        hub.notify(2)
+        hub.notify(3)
+        assert l == [1,2,3]
+
+    def test_multi_sub(self):
+        hub = py.event.Hub()
+        l1 = []
+        l2 = []
+        hub.append(l1.append) 
+        hub.append(l2.append) 
+        hub.notify(1)
+        hub.notify(2)
+        hub.notify(3)
+        assert l1 == [1,2,3]
+        assert l2 == [1,2,3]
+
+    def test_remove(self):
+        hub = py.event.Hub()
+        l = []
+        hub.append(l.append) 
+        hub.notify(1)
+        hub.remove(l.append) 
+        hub.notify(2)
+        assert l == [1]


More information about the py-svn mailing list