forked from tmux-python/libtmux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_test.py
87 lines (49 loc) · 1.37 KB
/
test_test.py
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
from time import time
import pytest
from libtmux.test import WaitTimeout, retry_until
def test_retry_three_times():
ini = time()
value = 0
def call_me_three_times():
nonlocal value
if value == 2:
return True
value += 1
return False
retry_until(call_me_three_times, 1)
end = time()
assert abs((end - ini) - 0.1) < 0.01
def test_function_times_out():
ini = time()
def never_true():
return False
with pytest.raises(WaitTimeout):
retry_until(never_true, 1)
end = time()
assert abs((end - ini) - 1.0) < 0.01
def test_function_times_out_no_rise():
ini = time()
def never_true():
return False
retry_until(never_true, 1, raises=False)
end = time()
assert abs((end - ini) - 1.0) < 0.01
def test_function_times_out_no_raise_assert():
ini = time()
def never_true():
return False
assert not retry_until(never_true, 1, raises=False)
end = time()
assert abs((end - ini) - 1.0) < 0.01
def test_retry_three_times_no_raise_assert():
ini = time()
value = 0
def call_me_three_times():
nonlocal value
if value == 2:
return True
value += 1
return False
assert retry_until(call_me_three_times, 1, raises=False)
end = time()
assert abs((end - ini) - 0.1) < 0.01