Ejemplo n.º 1
0
    def test_unregister_deletion(self):
        hook = HookMultiplexer()

        @hook
        def handler(event):
            event.handled = True

        event = hook.fire(name="handler")
        assert event.handled

        hook.unregister(handler)

        with pytest.raises(NameResolutionError):
            hook.fire(name="handler")
Ejemplo n.º 2
0
    def test_not_registered_unregister(self):
        hook = HookMultiplexer()

        @hook
        def handler1(event):
            event.handler1 = True

        def handler2(event):
            should_never_run()

        assert hook.fire(name="handler1").handler1

        with pytest.raises(NotRegisteredError):
            hook.unregister(handler2)
Ejemplo n.º 3
0
    def test_not_registered_unregister(self):
        hook = HookMultiplexer()

        @hook
        def handler1(event):
            event.handler1 = True

        def handler2(event):
            should_never_run()

        assert hook.fire(name="handler1").handler1
        
        with pytest.raises(NotRegisteredError):
            hook.unregister(handler2)
Ejemplo n.º 4
0
    def test_unregister_deletion(self):
        hook = HookMultiplexer()

        @hook
        def handler(event):
            event.handled = True

        event = hook.fire(name="handler")
        assert event.handled

        hook.unregister(handler)

        with pytest.raises(NameResolutionError):
            hook.fire(name="handler")
Ejemplo n.º 5
0
    def test_multi_unregister(self):
        hook = HookMultiplexer()

        @hook
        def handler1(event):
            should_never_run()

        @hook
        def handler2(event):
            event.handler2 = True

        hook.unregister(handler1)
        event = hook.fire(name="handler2")
        assert event.handler2

        with pytest.raises(NameResolutionError):
            hook.fire(name="handler1")
Ejemplo n.º 6
0
    def test_multi_unregister(self):
        hook = HookMultiplexer()

        @hook
        def handler1(event):
            should_never_run()

        @hook
        def handler2(event):
            event.handler2 = True

        hook.unregister(handler1)
        event = hook.fire(name="handler2")
        assert event.handler2

        with pytest.raises(NameResolutionError):
            hook.fire(name="handler1")
Ejemplo n.º 7
0
    def test_multi_unregister_samehook(self):
        hook = HookMultiplexer()
        counter = Counter()

        @hook("derp")
        def handler1(event):
            counter.tick()

        @hook("derp")
        def handler2(event):
            counter.tick()

        hook.fire(name="derp")
        assert counter.incremented(2)

        hook.unregister(handler1)
        hook.fire(name="derp")
        assert counter.incremented(1)

        hook.unregister(handler2)
        with pytest.raises(NameResolutionError):
            hook.fire(name="derp")
Ejemplo n.º 8
0
    def test_multi_unregister_samehook(self):
        hook = HookMultiplexer()
        counter = Counter()

        @hook("derp")
        def handler1(event):
            counter.tick()

        @hook("derp")
        def handler2(event):
            counter.tick()

        hook.fire(name="derp")
        assert counter.incremented(2)

        hook.unregister(handler1)
        hook.fire(name="derp")
        assert counter.incremented(1)

        hook.unregister(handler2)
        with pytest.raises(NameResolutionError):
            hook.fire(name="derp")