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

/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
 5"""Component Repr Tests
 6
 7Test Component's representation string.
 8"""
 9
10import os
11
12try:
13    from threading import current_thread
14except ImportError:
15    from threading import currentThread as current_thread  # NOQA
16
17from circuits import Event, Component
18
19
20class App(Component):
21
22    def test(self, event, *args, **kwargs):
23        pass
24
25
26class test(Event):
27    pass
28
29
30def test_main():
31    id = "%s:%s" % (os.getpid(), current_thread().getName())
32    app = App()
33
34    assert repr(app) == "<App/* %s (queued=0) [S]>" % id
35
36    app.fire(test())
37    assert repr(app) == "<App/* %s (queued=1) [S]>" % id
38
39    app.flush()
40    assert repr(app) == "<App/* %s (queued=0) [S]>" % id
41
42
43def test_non_str_channel():
44    id = "%s:%s" % (os.getpid(), current_thread().getName())
45    app = App(channel=(1, 1))
46
47    assert repr(app) == "<App/(1, 1) %s (queued=0) [S]>" % id
48
49    app.fire(test())
50    assert repr(app) == "<App/(1, 1) %s (queued=1) [S]>" % id
51
52    app.flush()
53    assert repr(app) == "<App/(1, 1) %s (queued=0) [S]>" % id