forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_failure.py
More file actions
140 lines (97 loc) · 3.27 KB
/
test_failure.py
File metadata and controls
140 lines (97 loc) · 3.27 KB
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
import logging
import time
import pytest
import progressbar
def test_missing_format_values(caplog) -> None:
caplog.set_level(logging.CRITICAL, logger='progressbar.widgets')
with pytest.raises(KeyError):
p = progressbar.ProgressBar(
widgets=[progressbar.widgets.FormatLabel('%(x)s')],
)
p.update(5)
def test_max_smaller_than_min() -> None:
with pytest.raises(ValueError):
progressbar.ProgressBar(min_value=10, max_value=5)
def test_no_max_value() -> None:
"""Looping up to 5 without max_value? No problem"""
p = progressbar.ProgressBar()
p.start()
for i in range(5):
time.sleep(1)
p.update(i)
def test_correct_max_value() -> None:
"""Looping up to 5 when max_value is 10? No problem"""
p = progressbar.ProgressBar(max_value=10)
for i in range(5):
time.sleep(1)
p.update(i)
def test_minus_max_value() -> None:
"""negative max_value, shouldn't work"""
p = progressbar.ProgressBar(min_value=-2, max_value=-1)
with pytest.raises(ValueError):
p.update(-1)
def test_zero_max_value() -> None:
"""max_value of zero, it could happen"""
p = progressbar.ProgressBar(max_value=0)
p.update(0)
with pytest.raises(ValueError):
p.update(1)
def test_one_max_value() -> None:
"""max_value of one, another corner case"""
p = progressbar.ProgressBar(max_value=1)
p.update(0)
p.update(0)
p.update(1)
with pytest.raises(ValueError):
p.update(2)
def test_changing_max_value() -> None:
"""Changing max_value? No problem"""
p = progressbar.ProgressBar(max_value=10)(range(20), max_value=20)
for _i in p:
time.sleep(1)
def test_backwards() -> None:
"""progressbar going backwards"""
p = progressbar.ProgressBar(max_value=1)
p.update(1)
p.update(0)
def test_incorrect_max_value() -> None:
"""Looping up to 10 when max_value is 5? This is madness!"""
p = progressbar.ProgressBar(max_value=5)
for i in range(5):
time.sleep(1)
p.update(i)
with pytest.raises(ValueError):
for i in range(5, 10):
time.sleep(1)
p.update(i)
def test_deprecated_maxval() -> None:
with pytest.warns(DeprecationWarning):
progressbar.ProgressBar(maxval=5)
def test_deprecated_poll() -> None:
with pytest.warns(DeprecationWarning):
progressbar.ProgressBar(poll=5)
def test_deprecated_currval() -> None:
with pytest.warns(DeprecationWarning):
bar = progressbar.ProgressBar(max_value=5)
bar.update(2)
assert bar.currval == 2
def test_unexpected_update_keyword_arg() -> None:
p = progressbar.ProgressBar(max_value=10)
with pytest.raises(TypeError):
for i in range(10):
time.sleep(1)
p.update(i, foo=10)
def test_variable_not_str() -> None:
with pytest.raises(TypeError):
progressbar.Variable(1)
def test_variable_too_many_strs() -> None:
with pytest.raises(ValueError):
progressbar.Variable('too long')
def test_negative_value() -> None:
bar = progressbar.ProgressBar(max_value=10)
with pytest.raises(ValueError):
bar.update(value=-1)
def test_increment() -> None:
bar = progressbar.ProgressBar(max_value=10)
bar.increment()
del bar