1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!/usr/bin/env python
import pytest
from circuits import handler, Component, Event
class wait(Event):
"""wait Event"""
success = True
class call(Event):
"""call Event"""
success = True
class long_call(Event):
"""long_call Event"""
success = True
class long_wait(Event):
"""long_wait Event"""
success = True
class wait_return(Event):
"""wait_return Event"""
success = True
class hello(Event):
"""hello Event"""
success = True
class foo(Event):
"""foo Event"""
success = True
class get_x(Event):
"""get_x Event"""
success = True
class get_y(Event):
"""get_y Event"""
success = True
class eval(Event):
"""eval Event"""
success = True
class App(Component):
@handler("wait")
def _on_wait(self):
x = self.fire(hello())
yield self.wait("hello")
yield x.value
@handler("call")
def _on_call(self):
x = yield self.call(hello())
yield x.value
def hello(self):
return "Hello World!"
def long_wait(self):
x = self.fire(foo())
yield self.wait("foo")
yield x.value
def wait_return(self):
self.fire(foo())
yield (yield self.wait("foo"))
def long_call(self):
x = yield self.call(foo())
yield x.value
def foo(self):
for i in range(1, 10):
yield i
def get_x(self):
return 1
def get_y(self):
return 2
def eval(self):
x = yield self.call(get_x())
y = yield self.call(get_y())
yield x.value + y.value
@pytest.fixture(scope="module")
def app(request, manager, watcher):
app = App().register(manager)
assert watcher.wait("registered")
def finalizer():
app.unregister()
request.addfinalizer(finalizer)
return app
def test_wait_simple(manager, watcher, app):
x = manager.fire(wait())
assert watcher.wait("wait_success")
value = x.value
assert value == "Hello World!"
def call_simple(manager, watcher, app):
x = manager.fire(call())
assert watcher.wait("call_success")
value = x.value
assert value == "Hello World!"
def test_long_call(manager, watcher, app):
x = manager.fire(long_call())
assert watcher.wait("long_call_success")
value = x.value
assert value == list(range(1, 10))
def test_long_wait(manager, watcher, app):
x = manager.fire(long_wait())
assert watcher.wait("long_wait_success")
value = x.value
assert value == list(range(1, 10))
def test_wait_return(manager, watcher, app):
x = manager.fire(wait_return())
assert watcher.wait("wait_return_success")
value = x.value
assert value == list(range(1, 10))
def test_eval(manager, watcher, app):
x = manager.fire(eval())
assert watcher.wait("eval_success")
value = x.value
assert value == 3
|