/tests/core/test_dynamic_handlers.py
https://bitbucket.org/prologic/circuits/ · Python · 57 lines · 33 code · 22 blank · 2 comment · 0 complexity · ff21fe7e74338b07b68f66d391e6ffed MD5 · raw file
- #!/usr/bin/env python
- import pytest
- from circuits import handler, Event, Manager
- class foo(Event):
- """foo Event"""
- @handler("foo")
- def on_foo(self):
- return "Hello World!"
- def test_addHandler():
- m = Manager()
- m.start()
- m.addHandler(on_foo)
- waiter = pytest.WaitEvent(m, "foo")
- x = m.fire(foo())
- waiter.wait()
- s = x.value
- assert s == "Hello World!"
- m.stop()
- def test_removeHandler():
- m = Manager()
- m.start()
- method = m.addHandler(on_foo)
- waiter = pytest.WaitEvent(m, "foo")
- x = m.fire(foo())
- waiter.wait()
- s = x.value
- assert s == "Hello World!"
- m.removeHandler(method)
- waiter = pytest.WaitEvent(m, "foo")
- x = m.fire(foo())
- waiter.wait()
- assert x.value is None
- assert on_foo not in dir(m)
- assert "foo" not in m._handlers
- m.stop()