]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_observer: improve test coverage
authorBrian Warner <warner@lothar.com>
Thu, 8 Mar 2007 23:13:14 +0000 (16:13 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 8 Mar 2007 23:13:14 +0000 (16:13 -0700)
src/allmydata/test/test_observer.py

index 4b12d041694404bd57c24c2456e80adc53043671..c70810129477b561a9ec65c0b800e66efbb6b796 100644 (file)
@@ -11,6 +11,7 @@ def nextTurn(res=None):
 class Observer(unittest.TestCase):
     def test_oneshot(self):
         ol = observer.OneShotObserverList()
+        rep = repr(ol)
         d1 = ol.when_fired()
         d2 = ol.when_fired()
         def _addmore(res):
@@ -20,6 +21,7 @@ class Observer(unittest.TestCase):
             return d3
         d1.addCallback(_addmore)
         ol.fire("result")
+        rep = repr(ol)
         d4 = ol.when_fired()
         dl = defer.DeferredList([d1,d2,d4])
         return dl
@@ -34,10 +36,27 @@ class Observer(unittest.TestCase):
             d2.addCallback(self.failUnlessEqual, "result")
             return d2
         d.addCallback(_addmore)
-        ol.fire("result")
+        ol.fire_if_not_fired("result")
         ol.fire_if_not_fired("result2")
         return d
 
+    def test_lazy_oneshot(self):
+        ol = observer.LazyOneShotObserverList()
+        d1 = ol.when_fired()
+        d2 = ol.when_fired()
+        def _addmore(res):
+            self.failUnlessEqual(res, "result")
+            d3 = ol.when_fired()
+            d3.addCallback(self.failUnlessEqual, "result")
+            return d3
+        d1.addCallback(_addmore)
+        def _get_result():
+            return "result"
+        ol.fire(_get_result)
+        d4 = ol.when_fired()
+        dl = defer.DeferredList([d1,d2,d4])
+        return dl
+
     def test_observerlist(self):
         ol = observer.ObserverList()
         l1 = []