forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_progressbar.py
More file actions
78 lines (59 loc) · 1.88 KB
/
test_progressbar.py
File metadata and controls
78 lines (59 loc) · 1.88 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
import contextlib
import os
import time
import original_examples # type: ignore
import pytest
import progressbar
# Import hack to allow for parallel Tox
try:
import examples
except ImportError:
import sys
_project_dir: str = os.path.dirname(os.path.dirname(__file__))
sys.path.append(_project_dir)
import examples
sys.path.remove(_project_dir)
def test_examples(monkeypatch) -> None:
for example in examples.examples:
with contextlib.suppress(ValueError):
example()
@pytest.mark.filterwarnings('ignore:.*maxval.*:DeprecationWarning')
@pytest.mark.parametrize('example', original_examples.examples)
def test_original_examples(example, monkeypatch) -> None:
monkeypatch.setattr(progressbar.ProgressBar, '_MINIMUM_UPDATE_INTERVAL', 1)
monkeypatch.setattr(time, 'sleep', lambda t: None)
example()
@pytest.mark.parametrize('example', examples.examples)
def test_examples_nullbar(monkeypatch, example) -> None:
# Patch progressbar to use null bar instead of regular progress bar
monkeypatch.setattr(progressbar, 'ProgressBar', progressbar.NullBar)
assert progressbar.ProgressBar._MINIMUM_UPDATE_INTERVAL < 0.0001
example()
def test_reuse() -> None:
bar = progressbar.ProgressBar()
bar.start()
for i in range(10):
bar.update(i)
bar.finish()
bar.start(init=True)
for i in range(10):
bar.update(i)
bar.finish()
bar.start(init=False)
for i in range(10):
bar.update(i)
bar.finish()
def test_dirty() -> None:
bar = progressbar.ProgressBar()
bar.start()
assert bar.started()
for i in range(10):
bar.update(i)
bar.finish(dirty=True)
assert bar.finished()
assert bar.started()
def test_negative_maximum() -> None:
with pytest.raises(ValueError), progressbar.ProgressBar(
max_value=-1
) as progress:
progress.start()