forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_timer.py
More file actions
45 lines (32 loc) · 1.38 KB
/
test_timer.py
File metadata and controls
45 lines (32 loc) · 1.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
from datetime import timedelta
import progressbar
def test_poll_interval():
# Test int, float and timedelta intervals
bar = progressbar.ProgressBar(poll_interval=1)
assert bar.poll_interval.seconds == 1
assert bar.poll_interval.microseconds == 0
bar = progressbar.ProgressBar(poll_interval=.001)
assert bar.poll_interval.seconds == 0
assert bar.poll_interval.microseconds < 1001
bar = progressbar.ProgressBar(poll_interval=timedelta(seconds=1))
assert bar.poll_interval.seconds == 1
assert bar.poll_interval.microseconds == 0
bar = progressbar.ProgressBar(poll_interval=timedelta(microseconds=1000))
assert bar.poll_interval.seconds == 0
assert bar.poll_interval.microseconds < 1001
def test_intervals():
bar = progressbar.ProgressBar(max_value=100)
bar._MINIMUM_UPDATE_INTERVAL = 1
# Initially there should be no last_update_time
assert bar.last_update_time is None
# After updating there should be a last_update_time
bar.update(1)
assert bar.last_update_time
# We should not need an update if the time is nearly the same as before
last_update_time = bar.last_update_time
bar.update(2)
assert bar.last_update_time == last_update_time
# We should need an update if we're beyond the poll_interval
bar._last_update_time -= 2
bar.update(3)
assert bar.last_update_time != last_update_time