-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathtest_unknown_length.py
More file actions
50 lines (39 loc) · 1.62 KB
/
Copy pathtest_unknown_length.py
File metadata and controls
50 lines (39 loc) · 1.62 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
import progressbar
def test_unknown_length() -> None:
pb = progressbar.ProgressBar(
widgets=[progressbar.AnimatedMarker()],
max_value=progressbar.UnknownLength,
)
assert pb.max_value is progressbar.UnknownLength
def test_unknown_length_default_widgets() -> None:
# The default widgets picked should work without a known max_value
pb = progressbar.ProgressBar(max_value=progressbar.UnknownLength).start()
for i in range(60):
pb.update(i)
pb.finish()
def test_unknown_length_at_start() -> None:
# The default widgets should be picked after we call .start()
pb = progressbar.ProgressBar().start(max_value=progressbar.UnknownLength)
for i in range(60):
pb.update(i)
pb.finish()
pb2 = progressbar.ProgressBar().start(max_value=progressbar.UnknownLength)
for w in pb2.widgets:
print(type(w), repr(w))
assert any(isinstance(w, progressbar.Bar) for w in pb2.widgets)
def test_unknown_length_redraws_on_value_change() -> None:
# With an unknown length and a non-time-sensitive widget (no
# `INTERVAL`), the bar still needs to redraw whenever the value
# advances; otherwise it would only ever show the start and finish
# values. See the `format_label` example.
pb = progressbar.ProgressBar(
widgets=[progressbar.FormatLabel('%(value)d')],
max_value=progressbar.UnknownLength,
).start()
assert pb.poll_interval is None
pb.previous_value = 2
pb.value = 3
# Make sure the min_poll_interval rate limit is not what blocks us
pb._last_update_timer -= 10
assert pb._needs_update() is True
pb.finish()