/tests/core/test_component_repr.py

https://bitbucket.org/prologic/circuits/ · Python · 53 lines · 24 code · 1 blank · 28 comment · 0 complexity · fd60fa952cf9f2ffd6cdd991e1ac953c MD5 · raw file

  1. # Module: test_component_repr
  2. # Date: 23rd February 2010
  3. # Author: James Mills, prologic at shortcircuit dot net dot au
  4. """Component Repr Tests
  5. Test Component's representation string.
  6. """
  7. import os
  8. try:
  9. from threading import current_thread
  10. except ImportError:
  11. from threading import currentThread as current_thread # NOQA
  12. from circuits import Event, Component
  13. class App(Component):
  14. def test(self, event, *args, **kwargs):
  15. pass
  16. class test(Event):
  17. pass
  18. def test_main():
  19. id = "%s:%s" % (os.getpid(), current_thread().getName())
  20. app = App()
  21. assert repr(app) == "<App/* %s (queued=0) [S]>" % id
  22. app.fire(test())
  23. assert repr(app) == "<App/* %s (queued=1) [S]>" % id
  24. app.flush()
  25. assert repr(app) == "<App/* %s (queued=0) [S]>" % id
  26. def test_non_str_channel():
  27. id = "%s:%s" % (os.getpid(), current_thread().getName())
  28. app = App(channel=(1, 1))
  29. assert repr(app) == "<App/(1, 1) %s (queued=0) [S]>" % id
  30. app.fire(test())
  31. assert repr(app) == "<App/(1, 1) %s (queued=1) [S]>" % id
  32. app.flush()
  33. assert repr(app) == "<App/(1, 1) %s (queued=0) [S]>" % id