forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_multibar.py
More file actions
104 lines (81 loc) · 2.38 KB
/
test_multibar.py
File metadata and controls
104 lines (81 loc) · 2.38 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
import threading
import time
import pytest
import progressbar
def test_multi_progress_bar_out_of_range():
widgets = [
progressbar.MultiProgressBar('multivalues'),
]
bar = progressbar.ProgressBar(widgets=widgets, max_value=10)
with pytest.raises(ValueError):
bar.update(multivalues=[123])
with pytest.raises(ValueError):
bar.update(multivalues=[-1])
def test_multi_progress_bar_fill_left():
import examples
return examples.multi_progress_bar_example(False)
def test_multibar():
bars = 3
N = 10
multibar = progressbar.MultiBar(sort_keyfunc=lambda bar: bar.label)
multibar.start()
multibar.append_label = False
multibar.prepend_label = True
# Test handling of progressbars that don't call the super constructors
bar = progressbar.ProgressBar(max_value=N)
bar.index = -1
multibar['x'] = bar
bar.start()
# Test twice for other code paths
multibar['x'] = bar
multibar._label_bar(bar)
multibar._label_bar(bar)
bar.finish()
del multibar['x']
multibar.append_label = True
def do_something(bar):
for j in bar(range(N)):
time.sleep(0.01)
bar.update(j)
for i in range(bars):
thread = threading.Thread(
target=do_something,
args=(multibar['bar {}'.format(i)],)
)
thread.start()
for bar in multibar.values():
for j in range(N):
bar.update(j)
time.sleep(0.002)
multibar.join(0.1)
multibar.stop(0.1)
@pytest.mark.parametrize(
'sort_key', [
None,
'index',
'label',
'value',
'percentage',
progressbar.SortKey.CREATED,
progressbar.SortKey.LABEL,
progressbar.SortKey.VALUE,
progressbar.SortKey.PERCENTAGE,
]
)
def test_multibar_sorting(sort_key):
bars = 3
N = 10
with progressbar.MultiBar() as multibar:
for i in range(bars):
label = f'bar {i}'
multibar[label] = progressbar.ProgressBar(max_value=N)
for bar in multibar.values():
for _ in bar(range(N)):
assert bar.started()
time.sleep(0.002)
for bar in multibar.values():
assert bar.finished()
def test_offset_bar():
with progressbar.ProgressBar(line_offset=2) as bar:
for i in range(100):
bar.update(i)