/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

  1. #!/usr/bin/env python
  2. import pytest
  3. from circuits import handler, Event, Manager
  4. class foo(Event):
  5. """foo Event"""
  6. @handler("foo")
  7. def on_foo(self):
  8. return "Hello World!"
  9. def test_addHandler():
  10. m = Manager()
  11. m.start()
  12. m.addHandler(on_foo)
  13. waiter = pytest.WaitEvent(m, "foo")
  14. x = m.fire(foo())
  15. waiter.wait()
  16. s = x.value
  17. assert s == "Hello World!"
  18. m.stop()
  19. def test_removeHandler():
  20. m = Manager()
  21. m.start()
  22. method = m.addHandler(on_foo)
  23. waiter = pytest.WaitEvent(m, "foo")
  24. x = m.fire(foo())
  25. waiter.wait()
  26. s = x.value
  27. assert s == "Hello World!"
  28. m.removeHandler(method)
  29. waiter = pytest.WaitEvent(m, "foo")
  30. x = m.fire(foo())
  31. waiter.wait()
  32. assert x.value is None
  33. assert on_foo not in dir(m)
  34. assert "foo" not in m._handlers
  35. m.stop()