PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/core/test_generator_value.py

https://bitbucket.org/prologic/circuits/
Python | 51 lines | 31 code | 17 blank | 3 comment | 3 complexity | 9af93e21990abab00f05df4680c9eb40 MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits import Event, Component
 4
 5
 6class test(Event):
 7    """test Event"""
 8
 9
10class hello(Event):
11    """hello Event"""
12
13
14class App(Component):
15
16    def test(self):
17        def f():
18            while True:
19                yield "Hello"
20        return f()
21
22    def hello(self):
23        yield "Hello "
24        yield "World!"
25
26
27def test_return_generator():
28    app = App()
29    while app:
30        app.flush()
31
32    v = app.fire(test())
33    app.tick()
34    app.tick()
35
36    x = v.value
37    assert x == "Hello"
38
39
40def test_yield():
41    app = App()
42    while app:
43        app.flush()
44
45    v = app.fire(hello())
46    app.tick()
47    app.tick()
48    app.tick()
49
50    x = v.value
51    assert x == ["Hello ", "World!"]