Skip to content

Commit fc5ac17

Browse files
committed
Fixed updates for non-timed progressbars. Fixes #185
1 parent 9fc4919 commit fc5ac17

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

progressbar/bar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ def _needs_update(self):
538538
divisor = self.max_value / self.term_width # float division
539539
if self.value // divisor == self.previous_value // divisor:
540540
return poll_status or self.end_time
541+
else:
542+
return True
541543
except Exception:
542544
# ignore any division errors
543545
pass

tests/test_monitor_progress.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,33 @@ def test_context_wrapper(testdir):
139139
' 80% (4 of 5) |##### | Elapsed Time: ?:00:04 ETA: ?:00:01',
140140
'100% (5 of 5) |#######| Elapsed Time: ?:00:05 Time: ?:00:05',
141141
])
142+
143+
144+
def test_non_timed(testdir):
145+
v = testdir.makepyfile('''
146+
import time
147+
import timeit
148+
import freezegun
149+
import progressbar
150+
151+
widgets = [progressbar.Percentage(), progressbar.Bar()]
152+
153+
with freezegun.freeze_time() as fake_time:
154+
timeit.default_timer = time.time
155+
with progressbar.ProgressBar(widgets=widgets, term_width=60) as bar:
156+
bar._MINIMUM_UPDATE_INTERVAL = 1e-9
157+
for _ in bar(list(range(5))):
158+
fake_time.tick(1)
159+
''')
160+
161+
result = testdir.runpython(v)
162+
result.stderr.lines = [l for l in result.stderr.lines if l.strip()]
163+
pprint.pprint(result.stderr.lines, width=70)
164+
result.stderr.fnmatch_lines([
165+
'N/A%| |',
166+
' 20%|########## |',
167+
' 40%|##################### |',
168+
' 60%|################################ |',
169+
' 80%|########################################### |',
170+
'100%|######################################################|',
171+
])

0 commit comments

Comments
 (0)