| 1 |
from unittest import TestCase, main |
| 2 |
|
| 3 |
import eventlet |
| 4 |
from eventlet import hubs |
| 5 |
from eventlet.hubs import timer |
| 6 |
|
| 7 |
|
| 8 |
class TestTimer(TestCase): |
| 9 |
def test_copy(self): |
| 10 |
t = timer.Timer(0, lambda: None) |
| 11 |
t2 = t.copy() |
| 12 |
assert t.seconds == t2.seconds |
| 13 |
assert t.tpl == t2.tpl |
| 14 |
assert t.called == t2.called |
| 15 |
|
| 16 |
def test_schedule(self): |
| 17 |
hub = hubs.get_hub() |
| 18 |
# clean up the runloop, preventing side effects from previous tests |
| 19 |
# on this thread |
| 20 |
if hub.running: |
| 21 |
hub.abort() |
| 22 |
eventlet.sleep(0) |
| 23 |
called = [] |
| 24 |
# t = timer.Timer(0, lambda: (called.append(True), hub.abort())) |
| 25 |
# t.schedule() |
| 26 |
# let's have a timer somewhere in the future; make sure abort() still works |
| 27 |
hubs.get_hub().schedule_call_global(0, lambda: (called.append(True), hub.abort())) |
| 28 |
hub.default_sleep = lambda: 0.0 |
| 29 |
hub.switch() |
| 30 |
assert called |
| 31 |
assert not hub.running |
| 32 |
|
| 33 |
|
| 34 |
if __name__ == '__main__': |
| 35 |
main() |