Exemplo n.º 1
0
    def test__logs_failures_from_cancellers(self):
        logger = self.useFixture(TwistedLoggerFixture())

        canceller = Mock()
        canceller.side_effect = factory.make_exception()

        dhooks = DeferredHooks()
        d = Deferred(canceller)
        dhooks.add(d)
        dhooks.reset()
        self.assertThat(dhooks.hooks, HasLength(0))
        # The hook has not been fired, but because the user-supplied canceller
        # has failed we're not in a position to know what to do. This reflects
        # a programming error and not a run-time error that we ought to be
        # prepared for, so it is left as-is.
        self.assertThat(d, IsUnfiredDeferred())
        self.assertDocTestMatches(
            dedent("""\
            Failure when cancelling hook.
            Traceback (most recent call last):
            ...
            maastesting.factory.TestException#...
            """),
            logger.output,
        )
Exemplo n.º 2
0
 def test_init(self):
     protocol = common.RPCProtocol()
     self.assertThat(protocol.onConnectionMade, IsUnfiredDeferred())
     self.assertThat(protocol.onConnectionLost, IsUnfiredDeferred())
     self.assertThat(protocol, IsInstance(amp.AMP))
Exemplo n.º 3
0
 def test__does_not_match_non_deferred(self):
     self.assertMismatch(IsUnfiredDeferred().match(object()),
                         " is not a Deferred")
Exemplo n.º 4
0
 def test__does_not_match_fired_deferred(self):
     d = defer.Deferred()
     d.callback(None)
     self.assertMismatch(IsUnfiredDeferred().match(d),
                         " has been called (result=None)")
Exemplo n.º 5
0
 def test__matches_unfired_deferred(self):
     d = defer.Deferred()
     self.assertThat(d, IsUnfiredDeferred())