Commits

Marcin Kasperski committed 462d8ff

work on deferred utils

  • Participants
  • Parent commits 93ab643

Comments (0)

Files changed (1)

tests/test_gather_defs.py

 import logging
 import os
 
-from twisted.internet import defer
+from twisted.internet import defer, reactor
 from twisted.trial import unittest
-from mekk.fics.twisted_util import delay_succeed, delay_exception
+from mekk.fics.twisted_util import delay_succeed, delay_exception, gather_safely
 
 if os.environ.get('DEBUG_REACTOR'):
     import twisted.internet.base
 class SomeExc(Exception):
     pass
 
-class DefDelayTestCase(unittest.TestCase):
+class DeferTestCase(unittest.TestCase):
     """
     Tests whether our test mechanique properly sync
     """
+
     @defer.inlineCallbacks
     def testDelayOks(self):
         x = yield delay_succeed("xyz")
         self.failUnlessEqual(r, ["first", "second"])
 
     @defer.inlineCallbacks
+    def testDelaySucceedDelays(self):
+        t1 = reactor.seconds()
+        x = yield delay_succeed("xyz", delay=0.1)
+        t2 = reactor.seconds()
+        self.failUnlessEqual(x, "xyz")
+        self.failUnless(t2 >= t1 + 0.1)
+
+    @defer.inlineCallbacks
     def testExcept(self):
         try:
             y = yield delay_exception(SomeExc())
             pass
 
     @defer.inlineCallbacks
+    def testExceptDelays(self):
+        t1 = reactor.seconds()
+        try:
+            y = yield delay_exception(SomeExc(), delay=0.1)
+            self.fail("No exception")
+        except SomeExc:
+            t2 = reactor.seconds()
+            self.failUnless(t2 >= t1 + 0.1)
+
+    @defer.inlineCallbacks
     def testOkAndExcept(self):
         try:
             x = yield delay_succeed("a")
 
     @defer.inlineCallbacks
     def testTwoExcept(self):
+        """
+        Wrong code which leaves reactor dirty
+        """
         try:
             x = delay_exception(SomeExc(), delay=0.2)
             y = delay_exception(SomeExc(), delay=0.05)
             pass
         self.failUnless(x.called)
         self.failUnless(y.called)
+    testTwoExcept.skip = "This is example of how bad code fails"
 
     @defer.inlineCallbacks
     def testGatherExcept(self):
+        """
+        Wrong code which leaves reactor dirty
+        """
         x = delay_succeed("beforee", delay=0.2)
         y = delay_exception(SomeExc(),delay=0.05)
         try:
         except SomeExc:
             pass
         self.failUnless(x.called)
+    testGatherExcept.skip = "This is example of bad code"
 
     @defer.inlineCallbacks
     def testGatherTwoExcept(self):
+        """
+        Wrong code which leaves reactor dirty
+        """
         x = delay_exception(SomeExc(), delay=0.2)
         y = delay_exception(SomeExc(),delay=0.05)
         try:
             pass
         self.failUnless(x.called)
         self.failUnless(y.called)
+    testGatherTwoExcept.skip = "This is example of bad code"
 
     @defer.inlineCallbacks
     def testProperlyGatherWithErr(self):