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")
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)
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")
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")