Debian Codegraph @

tests/test_timer.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 from datetime import timedelta
2
3 import pytest
4
5 import progressbar
6
7
8 @pytest.mark.parametrize(
9 'poll_interval,expected',
10 [
11 (1, 1),
12 (timedelta(seconds=1), 1),
13 (0.001, 0.001),
14 (timedelta(microseconds=1000), 0.001),
15 ],
16 )
17 @pytest.mark.parametrize(
18 'parameter',
19 [
20 'poll_interval',
21 'min_poll_interval',
22 ],
23 )
24 def test_poll_interval(parameter, poll_interval, expected) -> None:
25 # Test int, float and timedelta intervals
26 bar = progressbar.ProgressBar(**{parameter: poll_interval})
27 assert getattr(bar, parameter) == expected
28
29
30 @pytest.mark.parametrize(
31 'interval',
32 [
33 1,
34 timedelta(seconds=1),
35 ],
36 )
37 def test_intervals(monkeypatch, interval) -> None:
38 monkeypatch.setattr(
39 progressbar.ProgressBar,
40 '_MINIMUM_UPDATE_INTERVAL',
41 interval,
42 )
43 bar = progressbar.ProgressBar(max_value=100)
44
45 # Initially there should be no last_update_time
46 assert bar.last_update_time is None
47
48 # After updating there should be a last_update_time
49 bar.update(1)
50 assert bar.last_update_time
51
52 # We should not need an update if the time is nearly the same as before
53 last_update_time = bar.last_update_time
54 bar.update(2)
55 assert bar.last_update_time == last_update_time
56
57 # We should need an update if we're beyond the poll_interval
58 bar._last_update_time -= 2
59 bar.update(3)
60 assert bar.last_update_time != last_update_time