/tests/core/test_event.py

https://bitbucket.org/prologic/circuits/ · Python · 96 lines · 55 code · 36 blank · 5 comment · 4 complexity · 8bd3285ee493945145fc012065b61d1b MD5 · raw file

  1. # Module: test_event
  2. # Date: 12th April 2010
  3. # Author: James Mills, prologic at shortcircuit dot net dot au
  4. """Event Tests"""
  5. import py
  6. from circuits import Event, Component
  7. class test(Event):
  8. """test Event"""
  9. class App(Component):
  10. def test(self):
  11. return "Hello World!"
  12. def test_repr():
  13. app = App()
  14. while app:
  15. app.flush()
  16. e = test()
  17. s = repr(e)
  18. assert s == "<test[] ( )>"
  19. app.fire(e)
  20. s = repr(e)
  21. assert s == "<test[*] ( )>"
  22. def test_create():
  23. app = App()
  24. while app:
  25. app.flush()
  26. e = Event.create("test")
  27. s = repr(e)
  28. assert s == "<test[] ( )>"
  29. app.fire(e)
  30. s = repr(e)
  31. assert s == "<test[*] ( )>"
  32. def test_getitem():
  33. app = App()
  34. while app:
  35. app.flush()
  36. e = test(1, 2, 3, foo="bar")
  37. assert e[0] == 1
  38. assert e["foo"] == "bar"
  39. def f(e, k):
  40. return e[k]
  41. py.test.raises(TypeError, f, e, None)
  42. def test_setitem():
  43. app = App()
  44. while app:
  45. app.flush()
  46. e = test(1, 2, 3, foo="bar")
  47. assert e[0] == 1
  48. assert e["foo"] == "bar"
  49. e[0] = 0
  50. e["foo"] = "Hello"
  51. def f(e, k, v):
  52. e[k] = v
  53. py.test.raises(TypeError, f, e, None, None)
  54. assert e[0] == 0
  55. assert e["foo"] == "Hello"
  56. def test_subclass_looses_properties():
  57. class hello(Event):
  58. success = True
  59. e = hello().child('success')
  60. assert e.success is False