def test_basic(): values = [] @hooks.hook("test_basic") def test(name): values.append(name) hooks.run("test_basic", "Bobby") hooks.run("test_basic", "Johnny") assert len(values) == 2 assert values == ["Bobby", "Johnny"]
def test_compatibility(): values = [] def test(info): name, = hooks.parse_info(info) values.append(name) hooks.add("test_compatibility", test) hooks.run("test_compatibility", hooks.build_info("str", ("Bobby", ))) hooks.run("test_compatibility", hooks.build_info("str", ("Johnny", ))) assert len(values) == 2 assert values == ["Bobby", "Johnny"]
def test_stopprop(): values = [] @hooks.hook("test_stopprop") def test(name): values.append(name) @hooks.hook("test_stopprop", priority=1) def tester(name): raise StopIteration hooks.run("test_stopprop", "Bobby") hooks.run("test_stopprop", "Johnny") assert len(values) == 0
def test_priority(): values = [] @hooks.hook("test_priority") def test(name): values.append(name) @hooks.hook("test_priority", priority=1) def tester(name): values.append("corn") hooks.run("test_priority", "Steve") assert len(values) == 2 assert values == ["corn", "Steve"]