Debian Codegraph @

tests/test_failure.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import logging
2 import time
3
4 import pytest
5
6 import progressbar
7
8
9 def test_missing_format_values(caplog) -> None:
10 caplog.set_level(logging.CRITICAL, logger='progressbar.widgets')
11 with pytest.raises(KeyError):
12 p = progressbar.ProgressBar(
13 widgets=[progressbar.widgets.FormatLabel('%(x)s')],
14 )
15 p.update(5)
16
17
18 def test_max_smaller_than_min() -> None:
19 with pytest.raises(ValueError):
20 progressbar.ProgressBar(min_value=10, max_value=5)
21
22
23 def test_no_max_value() -> None:
24 """Looping up to 5 without max_value? No problem"""
25 p = progressbar.ProgressBar()
26 p.start()
27 for i in range(5):
28 time.sleep(1)
29 p.update(i)
30
31
32 def test_correct_max_value() -> None:
33 """Looping up to 5 when max_value is 10? No problem"""
34 p = progressbar.ProgressBar(max_value=10)
35 for i in range(5):
36 time.sleep(1)
37 p.update(i)
38
39
40 def test_minus_max_value() -> None:
41 """negative max_value, shouldn't work"""
42 p = progressbar.ProgressBar(min_value=-2, max_value=-1)
43
44 with pytest.raises(ValueError):
45 p.update(-1)
46
47
48 def test_zero_max_value() -> None:
49 """max_value of zero, it could happen"""
50 p = progressbar.ProgressBar(max_value=0)
51
52 p.update(0)
53 with pytest.raises(ValueError):
54 p.update(1)
55
56
57 def test_one_max_value() -> None:
58 """max_value of one, another corner case"""
59 p = progressbar.ProgressBar(max_value=1)
60
61 p.update(0)
62 p.update(0)
63 p.update(1)
64 with pytest.raises(ValueError):
65 p.update(2)
66
67
68 def test_changing_max_value() -> None:
69 """Changing max_value? No problem"""
70 p = progressbar.ProgressBar(max_value=10)(range(20), max_value=20)
71 for _i in p:
72 time.sleep(1)
73
74
75 def test_backwards() -> None:
76 """progressbar going backwards"""
77 p = progressbar.ProgressBar(max_value=1)
78
79 p.update(1)
80 p.update(0)
81
82
83 def test_incorrect_max_value() -> None:
84 """Looping up to 10 when max_value is 5? This is madness!"""
85 p = progressbar.ProgressBar(max_value=5)
86 for i in range(5):
87 time.sleep(1)
88 p.update(i)
89
90 with pytest.raises(ValueError):
91 for i in range(5, 10):
92 time.sleep(1)
93 p.update(i)
94
95
96 def test_deprecated_maxval() -> None:
97 with pytest.warns(DeprecationWarning):
98 progressbar.ProgressBar(maxval=5)
99
100
101 def test_deprecated_poll() -> None:
102 with pytest.warns(DeprecationWarning):
103 progressbar.ProgressBar(poll=5)
104
105
106 def test_deprecated_currval() -> None:
107 with pytest.warns(DeprecationWarning):
108 bar = progressbar.ProgressBar(max_value=5)
109 bar.update(2)
110 assert bar.currval == 2
111
112
113 def test_unexpected_update_keyword_arg() -> None:
114 p = progressbar.ProgressBar(max_value=10)
115 with pytest.raises(TypeError):
116 for i in range(10):
117 time.sleep(1)
118 p.update(i, foo=10)
119
120
121 def test_variable_not_str() -> None:
122 with pytest.raises(TypeError):
123 progressbar.Variable(1)
124
125
126 def test_variable_too_many_strs() -> None:
127 with pytest.raises(ValueError):
128 progressbar.Variable('too long')
129
130
131 def test_negative_value() -> None:
132 bar = progressbar.ProgressBar(max_value=10)
133 with pytest.raises(ValueError):
134 bar.update(value=-1)
135
136
137 def test_increment() -> None:
138 bar = progressbar.ProgressBar(max_value=10)
139 bar.increment()
140 del bar