Debian Codegraph @

tests/timeout_test.py

raw
1 import eventlet
2
3 import tests
4
5
6 DELAY = 0.01
7
8
9 class TestDirectRaise(tests.LimitedTestCase):
10 def test_direct_raise_class(self):
11 try:
12 raise eventlet.Timeout
13 except eventlet.Timeout as t:
14 assert not t.pending, repr(t)
15
16 def test_direct_raise_instance(self):
17 tm = eventlet.Timeout()
18 try:
19 raise tm
20 except eventlet.Timeout as t:
21 assert tm is t, (tm, t)
22 assert not t.pending, repr(t)
23
24 def test_repr(self):
25 # just verify these don't crash
26 tm = eventlet.Timeout(1)
27 eventlet.sleep(0)
28 repr(tm)
29 str(tm)
30 tm.cancel()
31 tm = eventlet.Timeout(None, RuntimeError)
32 repr(tm)
33 str(tm)
34 tm = eventlet.Timeout(None, False)
35 repr(tm)
36 str(tm)
37
38
39 class TestWithTimeout(tests.LimitedTestCase):
40 def test_with_timeout(self):
41 self.assertRaises(eventlet.Timeout, eventlet.with_timeout, DELAY, eventlet.sleep, DELAY * 10)
42 X = object()
43 r = eventlet.with_timeout(DELAY, eventlet.sleep, DELAY * 10, timeout_value=X)
44 assert r is X, (r, X)
45 r = eventlet.with_timeout(DELAY * 10, eventlet.sleep, DELAY, timeout_value=X)
46 assert r is None, r
47
48 def test_with_outer_timer(self):
49 def longer_timeout():
50 # this should not catch the outer timeout's exception
51 return eventlet.with_timeout(DELAY * 10, eventlet.sleep, DELAY * 20, timeout_value='b')
52 self.assertRaises(
53 eventlet.Timeout,
54 eventlet.with_timeout,
55 DELAY, longer_timeout)
56
57
58 def test_is_timeout_attribute():
59 tests.check_is_timeout(eventlet.Timeout())