コード例 #1
0
ファイル: test_defer.py プロジェクト: rwarren/deferred
    def test_comparison(self):
        """
        L{FirstError} instances compare equal to each other if and only if
        their failure and index compare equal.  L{FirstError} instances do not
        compare equal to instances of other types.
        """
        try:
            1 / 0
        except:
            firstFailure = Failure()

        one = deferred.FirstError(firstFailure, 13)
        anotherOne = deferred.FirstError(firstFailure, 13)

        try:
            raise ValueError("bar")
        except:
            secondFailure = Failure()

        another = deferred.FirstError(secondFailure, 9)

        self.assertTrue(one == anotherOne)
        self.assertFalse(one == another)
        self.assertTrue(one != another)
        self.assertFalse(one != anotherOne)

        self.assertFalse(one == 10)
コード例 #2
0
ファイル: test_defer.py プロジェクト: rwarren/deferred
 def test_maybeDeferredAsyncError(self):
     """
     L{deferred.maybeDeferred} should let L{deferred.Deferred} instance pass by
     so that L{Failure} returned by the original instance is the
     same.
     """
     d = deferred.Deferred()
     d2 = deferred.maybeDeferred(lambda: d)
     d.errback(Failure(RuntimeError()))
     return self.assertFailure(d2, RuntimeError)
コード例 #3
0
ファイル: test_defer.py プロジェクト: rwarren/deferred
 def testCallbackErrors(self):
     l = []
     d = deferred.Deferred().addCallback(lambda _: 1 / 0).addErrback(
         l.append)
     d.callback(1)
     self.assert_(isinstance(l[0].value, ZeroDivisionError))
     l = []
     d = deferred.Deferred().addCallback(
         lambda _: Failure(ZeroDivisionError())).addErrback(l.append)
     d.callback(1)
     self.assert_(isinstance(l[0].value, ZeroDivisionError))
コード例 #4
0
ファイル: test_defer.py プロジェクト: rwarren/deferred
    def test_str(self):
        """
        The str of a L{FirstError} instance includes the str of the
        sub-failure and the index which corresponds to the L{FirstError}.
        """
        exc = ValueError("some text")
        try:
            raise exc
        except:
            f = Failure()

        error = deferred.FirstError(f, 5)
        self.assertEqual(str(error), "FirstError[#5, %s]" % (str(f), ))
コード例 #5
0
ファイル: test_defer.py プロジェクト: rwarren/deferred
 def _err_2(self, d):
     d.errback(Failure(RuntimeError()))