Debian Codegraph @

tests/test_progressbar.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 import contextlib
2 import os
3 import time
4
5 import original_examples # type: ignore
6 import pytest
7
•8 import progressbar2
9
10 # Import hack to allow for parallel Tox
11 try:
12 import examples
13 except ImportError:
14 import sys
15
16 _project_dir: str = os.path.dirname(os.path.dirname(__file__))
17 sys.path.append(_project_dir)
18 import examples
19
20 sys.path.remove(_project_dir)
21
22
23 def test_examples(monkeypatch) -> None:
24 for example in examples.examples:
25 with contextlib.suppress(ValueError):
26 example()
27
28
29 @pytest.mark.filterwarnings('ignore:.*maxval.*:DeprecationWarning')
30 @pytest.mark.parametrize('example', original_examples.examples)
31 def test_original_examples(example, monkeypatch) -> None:
•32 monkeypatch.setattr(progressbar2.ProgressBar, '_MINIMUM_UPDATE_INTERVAL', 1)
33 monkeypatch.setattr(time, 'sleep', lambda t: None)
34 example()
35
36
37 @pytest.mark.parametrize('example', examples.examples)
38 def test_examples_nullbar(monkeypatch, example) -> None:
39 # Patch progressbar to use null bar instead of regular progress bar
•40 monkeypatch.setattr(progressbar2, 'ProgressBar', progressbar2.NullBar)
41 assert progressbar2.ProgressBar._MINIMUM_UPDATE_INTERVAL < 0.0001
42 example()
43
44
45 def test_reuse() -> None:
•46 bar = progressbar2.ProgressBar()
47 bar.start()
48 for i in range(10):
49 bar.update(i)
50 bar.finish()
51
52 bar.start(init=True)
53 for i in range(10):
54 bar.update(i)
55 bar.finish()
56
57 bar.start(init=False)
58 for i in range(10):
59 bar.update(i)
60 bar.finish()
61
62
63 def test_dirty() -> None:
•64 bar = progressbar2.ProgressBar()
65 bar.start()
66 assert bar.started()
67 for i in range(10):
68 bar.update(i)
69 bar.finish(dirty=True)
70 assert bar.finished()
71 assert bar.started()
72
73
74 def test_negative_maximum() -> None:
•75 with pytest.raises(ValueError), progressbar2.ProgressBar(
76 max_value=-1
77 ) as progress:
78 progress.start()