Ejemplo n.º 1
0
    def test__savepoint_saves_and_restores_hooks(self):
        d = Deferred()
        dhooks = DeferredHooks()
        dhooks.add(d)

        with dhooks.savepoint():
            self.expectThat(list(dhooks.hooks), Equals([]))

        self.expectThat(list(dhooks.hooks), Equals([d]))
Ejemplo n.º 2
0
    def test__savepoint_restores_hooks_with_new_hooks_on_clean_exit(self):
        d1 = Deferred()
        d2 = Deferred()
        dhooks = DeferredHooks()
        dhooks.add(d1)

        with dhooks.savepoint():
            dhooks.add(d2)
            self.expectThat(list(dhooks.hooks), Equals([d2]))

        self.expectThat(list(dhooks.hooks), Equals([d1, d2]))
Ejemplo n.º 3
0
    def test__savepoint_restores_hooks_only_on_dirty_exit(self):
        d1 = Deferred()
        d2 = Deferred()
        dhooks = DeferredHooks()
        dhooks.add(d1)

        exception_type = factory.make_exception_type()
        with ExpectedException(exception_type):
            with dhooks.savepoint():
                dhooks.add(d2)
                raise exception_type()

        self.expectThat(list(dhooks.hooks), Equals([d1]))