FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-progressbar/tests/test_monitor_progress.py at develop · KarrLab/python-progressbar · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
KarrLab
/
python-progressbar
Public
forked from
wolph/python-progressbar
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-progressbar
/
tests
/
test_monitor_progress.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
171 lines (147 loc) · 6.71 KB
Breadcrumbs
python-progressbar
/
tests
/
test_monitor_progress.py
Copy path
File metadata and controls
171 lines (147 loc) · 6.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import
pprint
pytest_plugins
=
'pytester'
def
test_list_example
(
testdir
):
''' Run the simple example code in a python subprocess and then compare its
stderr to what we expect to see from it. We run it in a subprocess to
best capture its stderr. We expect to see match_lines in order in the
output. This test is just a sanity check to ensure that the progress
bar progresses from 1 to 10, it does not make sure that the '''
v
=
testdir
.
makepyfile
(
'''
import time
import timeit
import freezegun
import progressbar
with freezegun.freeze_time() as fake_time:
timeit.default_timer = time.time
bar = progressbar.ProgressBar(term_width=65)
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
for i in bar(list(range(9))):
fake_time.tick(1)
'''
)
result
=
testdir
.
runpython
(
v
)
result
.
stderr
.
lines
=
[
l
.
rstrip
()
for
l
in
result
.
stderr
.
lines
if
l
.
strip
()]
pprint
.
pprint
(
result
.
stderr
.
lines
,
width
=
70
)
result
.
stderr
.
fnmatch_lines
([
'N/A% (0 of 9) | | Elapsed Time: ?:00:00 ETA: --:--:--'
,
' 11% (1 of 9) |# | Elapsed Time: ?:00:01 ETA: ?:00:08'
,
' 22% (2 of 9) |## | Elapsed Time: ?:00:02 ETA: ?:00:07'
,
' 33% (3 of 9) |#### | Elapsed Time: ?:00:03 ETA: ?:00:06'
,
' 44% (4 of 9) |##### | Elapsed Time: ?:00:04 ETA: ?:00:05'
,
' 55% (5 of 9) |###### | Elapsed Time: ?:00:05 ETA: ?:00:04'
,
' 66% (6 of 9) |######## | Elapsed Time: ?:00:06 ETA: ?:00:03'
,
' 77% (7 of 9) |######### | Elapsed Time: ?:00:07 ETA: ?:00:02'
,
' 88% (8 of 9) |########## | Elapsed Time: ?:00:08 ETA: ?:00:01'
,
'100% (9 of 9) |############| Elapsed Time: ?:00:09 Time: ?:00:09'
,
])
def
test_generator_example
(
testdir
):
''' Run the simple example code in a python subprocess and then compare its
stderr to what we expect to see from it. We run it in a subprocess to
best capture its stderr. We expect to see match_lines in order in the
output. This test is just a sanity check to ensure that the progress
bar progresses from 1 to 10, it does not make sure that the '''
v
=
testdir
.
makepyfile
(
'''
import time
import timeit
import freezegun
import progressbar
with freezegun.freeze_time() as fake_time:
timeit.default_timer = time.time
bar = progressbar.ProgressBar(term_width=60)
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
for i in bar(iter(range(9))):
fake_time.tick(1)
'''
)
result
=
testdir
.
runpython
(
v
)
result
.
stderr
.
lines
=
[
l
for
l
in
result
.
stderr
.
lines
if
l
.
strip
()]
pprint
.
pprint
(
result
.
stderr
.
lines
,
width
=
70
)
lines
=
[]
for
i
in
range
(
9
):
lines
.
append
(
r'[/\\|\-]\s+\|\s*#\s*\| %(i)d Elapsed Time: \d:00:%(i)02d'
%
dict
(
i
=
i
))
result
.
stderr
.
re_match_lines
(
lines
)
def
test_rapid_updates
(
testdir
):
''' Run some example code that updates 10 times, then sleeps .1 seconds,
this is meant to test that the progressbar progresses normally with
this sample code, since there were issues with it in the past '''
v
=
testdir
.
makepyfile
(
'''
import time
import timeit
import freezegun
import progressbar
with freezegun.freeze_time() as fake_time:
timeit.default_timer = time.time
bar = progressbar.ProgressBar(term_width=60)
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
for i in bar(range(10)):
if i < 5:
fake_time.tick(1)
else:
fake_time.tick(2)
'''
)
result
=
testdir
.
runpython
(
v
)
result
.
stderr
.
lines
=
[
l
for
l
in
result
.
stderr
.
lines
if
l
.
strip
()]
pprint
.
pprint
(
result
.
stderr
.
lines
,
width
=
70
)
result
.
stderr
.
fnmatch_lines
([
'N/A% (0 of 10) | | Elapsed Time: ?:00:00 ETA: --:--:--'
,
' 10% (1 of 10) | | Elapsed Time: ?:00:01 ETA: ?:00:09'
,
' 20% (2 of 10) |# | Elapsed Time: ?:00:02 ETA: ?:00:08'
,
' 30% (3 of 10) |# | Elapsed Time: ?:00:03 ETA: ?:00:07'
,
' 40% (4 of 10) |## | Elapsed Time: ?:00:04 ETA: ?:00:06'
,
' 50% (5 of 10) |### | Elapsed Time: ?:00:05 ETA: ?:00:05'
,
' 60% (6 of 10) |### | Elapsed Time: ?:00:07 ETA: ?:00:06'
,
' 70% (7 of 10) |#### | Elapsed Time: ?:00:09 ETA: ?:00:06'
,
' 80% (8 of 10) |#### | Elapsed Time: ?:00:11 ETA: ?:00:04'
,
' 90% (9 of 10) |##### | Elapsed Time: ?:00:13 ETA: ?:00:02'
,
'100% (10 of 10) |#####| Elapsed Time: ?:00:15 Time: ?:00:15'
])
def
test_context_wrapper
(
testdir
):
v
=
testdir
.
makepyfile
(
'''
import time
import timeit
import freezegun
import progressbar
with freezegun.freeze_time() as fake_time:
timeit.default_timer = time.time
with progressbar.ProgressBar(term_width=60) as bar:
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
for _ in bar(list(range(5))):
fake_time.tick(1)
'''
)
result
=
testdir
.
runpython
(
v
)
result
.
stderr
.
lines
=
[
l
for
l
in
result
.
stderr
.
lines
if
l
.
strip
()]
pprint
.
pprint
(
result
.
stderr
.
lines
,
width
=
70
)
result
.
stderr
.
fnmatch_lines
([
'N/A% (0 of 5) | | Elapsed Time: ?:00:00 ETA: --:--:--'
,
' 20% (1 of 5) |# | Elapsed Time: ?:00:01 ETA: ?:00:04'
,
' 40% (2 of 5) |## | Elapsed Time: ?:00:02 ETA: ?:00:03'
,
' 60% (3 of 5) |#### | Elapsed Time: ?:00:03 ETA: ?:00:02'
,
' 80% (4 of 5) |##### | Elapsed Time: ?:00:04 ETA: ?:00:01'
,
'100% (5 of 5) |#######| Elapsed Time: ?:00:05 Time: ?:00:05'
,
])
def
test_non_timed
(
testdir
):
v
=
testdir
.
makepyfile
(
'''
import time
import timeit
import freezegun
import progressbar
widgets = [progressbar.Percentage(), progressbar.Bar()]
with freezegun.freeze_time() as fake_time:
timeit.default_timer = time.time
with progressbar.ProgressBar(widgets=widgets, term_width=60) as bar:
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
for _ in bar(list(range(5))):
fake_time.tick(1)
'''
)
result
=
testdir
.
runpython
(
v
)
result
.
stderr
.
lines
=
[
l
for
l
in
result
.
stderr
.
lines
if
l
.
strip
()]
pprint
.
pprint
(
result
.
stderr
.
lines
,
width
=
70
)
result
.
stderr
.
fnmatch_lines
([
'N/A%| |'
,
' 20%|########## |'
,
' 40%|##################### |'
,
' 60%|################################ |'
,
' 80%|########################################### |'
,
'100%|######################################################|'
,
])
Back
|
FazBrowse Home
|
New Git URL