def test_dispatch(): global called_default called_default = False def handler_default(*args, **kwargs): global called_default called_default = True return global called called = False def handler(*args, **kwargs): global called called = True return args[0] hooks.register_default("test_hook", handler_default) hooks.register("test_hook", handler) hooks.dispatch("test_hook", 1) assert not called_default assert called called_default = False called = False hooks.dispatch("test_hook", None) assert called_default assert called
def test_register(): assert "test_hook" not in hooks._handlers assert "test_hook" not in hooks._defaults with assert_raises(error.InvalidHook): hooks.register("test_hook", lambda x: x) assert "test_hook" not in hooks._handlers assert "test_hook" not in hooks._defaults hooks.register_default("test_hook", lambda x: x) hooks.register("test_hook", lambda x: x) assert "test_hook" in hooks._handlers
def bootstrap(config_dir=None): core.init(config_dir) register_default('decode_data', hook_decode_data) register_default('encode_data', hook_encode_data)
def test_register_default(): assert "test_hook" not in hooks._defaults hooks.register_default("test_hook", None) assert "test_hook" in hooks._defaults