PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/core/test_dynamic_handlers.py

https://bitbucket.org/prologic/circuits/
Python | 57 lines | 33 code | 22 blank | 2 comment | 4 complexity | ff21fe7e74338b07b68f66d391e6ffed MD5 | raw file
 1#!/usr/bin/env python
 2
 3import pytest
 4
 5from circuits import handler, Event, Manager
 6
 7
 8class foo(Event):
 9    """foo Event"""
10
11
12@handler("foo")
13def on_foo(self):
14    return "Hello World!"
15
16
17def test_addHandler():
18    m = Manager()
19    m.start()
20
21    m.addHandler(on_foo)
22
23    waiter = pytest.WaitEvent(m, "foo")
24    x = m.fire(foo())
25    waiter.wait()
26
27    s = x.value
28    assert s == "Hello World!"
29
30    m.stop()
31
32
33def test_removeHandler():
34    m = Manager()
35    m.start()
36
37    method = m.addHandler(on_foo)
38
39    waiter = pytest.WaitEvent(m, "foo")
40    x = m.fire(foo())
41    waiter.wait()
42
43    s = x.value
44    assert s == "Hello World!"
45
46    m.removeHandler(method)
47
48    waiter = pytest.WaitEvent(m, "foo")
49    x = m.fire(foo())
50    waiter.wait()
51
52    assert x.value is None
53
54    assert on_foo not in dir(m)
55    assert "foo" not in m._handlers
56
57    m.stop()