PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 5"""Event Tests"""
 6
 7import py
 8
 9from circuits import Event, Component
10
11
12class test(Event):
13    """test Event"""
14
15
16class App(Component):
17
18    def test(self):
19        return "Hello World!"
20
21
22def test_repr():
23    app = App()
24    while app:
25        app.flush()
26
27    e = test()
28
29    s = repr(e)
30    assert s == "<test[] ( )>"
31
32    app.fire(e)
33
34    s = repr(e)
35    assert s == "<test[*] ( )>"
36
37
38def test_create():
39    app = App()
40    while app:
41        app.flush()
42
43    e = Event.create("test")
44
45    s = repr(e)
46    assert s == "<test[] ( )>"
47
48    app.fire(e)
49
50    s = repr(e)
51    assert s == "<test[*] ( )>"
52
53
54def test_getitem():
55    app = App()
56    while app:
57        app.flush()
58
59    e = test(1, 2, 3, foo="bar")
60
61    assert e[0] == 1
62    assert e["foo"] == "bar"
63
64    def f(e, k):
65        return e[k]
66
67    py.test.raises(TypeError, f, e, None)
68
69
70def test_setitem():
71    app = App()
72    while app:
73        app.flush()
74
75    e = test(1, 2, 3, foo="bar")
76
77    assert e[0] == 1
78    assert e["foo"] == "bar"
79
80    e[0] = 0
81    e["foo"] = "Hello"
82
83    def f(e, k, v):
84        e[k] = v
85
86    py.test.raises(TypeError, f, e, None, None)
87
88    assert e[0] == 0
89    assert e["foo"] == "Hello"
90
91
92def test_subclass_looses_properties():
93    class hello(Event):
94        success = True
95    e = hello().child('success')
96    assert e.success is False