Skip to content

Commit

Permalink
Fixed updates for non-timed progressbars. Fixes #185
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Mar 13, 2019
1 parent 9fc4919 commit fc5ac17
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions progressbar/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ def _needs_update(self):
divisor = self.max_value / self.term_width # float division
if self.value // divisor == self.previous_value // divisor:
return poll_status or self.end_time
else:
return True
except Exception:
# ignore any division errors
pass
Expand Down
30 changes: 30 additions & 0 deletions tests/test_monitor_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,33 @@ def test_context_wrapper(testdir):
' 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%|######################################################|',
])

0 comments on commit fc5ac17

Please sign in to comment.