PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/core/test_manager_repr.py

https://bitbucket.org/prologic/circuits/
Python | 49 lines | 25 code | 1 blank | 23 comment | 0 complexity | 7112551848f6e9b83fece8c5d9da857a MD5 | raw file
 1# Module:   test_manager_repr
 2# Date:     23rd February 2010
 3# Author:   James Mills, prologic at shortcircuit dot net dot au
 4
 5"""Manager Repr Tests
 6
 7Test Manager's representation string.
 8"""
 9
10import os
11from time import sleep
12from threading import current_thread
13
14import pytest
15
16from circuits import Component, Manager
17
18
19class App(Component):
20
21    def test(self, event, *args, **kwargs):
22        pass
23
24
25def test_main():
26    id = "%s:%s" % (os.getpid(), current_thread().getName())
27
28    m = Manager()
29    assert repr(m) == "<Manager/ %s (queued=0) [S]>" % id
30
31    app = App()
32    app.register(m)
33    s = repr(m)
34    assert s == "<Manager/ %s (queued=1) [S]>" % id
35
36    m.start()
37
38    pytest.wait_for(m, "_running", True)
39    sleep(0.1)
40
41    s = repr(m)
42    assert s == "<Manager/ %s (queued=0) [R]>" % id
43
44    m.stop()
45
46    pytest.wait_for(m, "_Manager__thread", None)
47
48    s = repr(m)
49    assert s == "<Manager/ %s (queued=0) [S]>" % id