FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fixed 100% progressbar, relocated tests and improved several tests. f… · reuben/python-progressbar@d00e256 · GitHub

Commit d00e256

Browse files
committed
fixed 100% progressbar, relocated tests and improved several tests. fixes wolph#108
1 parent 54fb8ff commit d00e256

23 files changed

Lines changed: 52 additions & 12 deletions

‎.travis.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ install:
1212
before_script: flake8 --ignore=W391 progressbar tests
1313
script:
1414
- python setup.py test
15+
- python examples.py
1516
after_success:
1617
- coveralls

‎examples.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def wrapped():
3434
except KeyboardInterrupt:
3535
sys.stdout.write('\nSkipping example.\n\n')
3636
# Sleep a bit to make killing the script easier
37-
time.sleep(0.2)
37+
sleep(0.2)
3838

3939
examples.append(wrapped)
4040
return wrapped
@@ -329,15 +329,15 @@ def rotating_bouncing_marker():
329329
with progressbar.ProgressBar(widgets=widgets, max_value=20,
330330
term_width=10) as progress:
331331
for i in range(20):
332-
time.sleep(0.1)
332+
sleep(0.1)
333333
progress.update(i)
334334

335335
widgets = [progressbar.BouncingBar(marker=progressbar.RotatingMarker(),
336336
fill_left=False)]
337337
with progressbar.ProgressBar(widgets=widgets, max_value=20,
338338
term_width=10) as progress:
339339
for i in range(20):
340-
time.sleep(0.1)
340+
sleep(0.1)
341341
progress.update(i)
342342

343343

@@ -469,7 +469,7 @@ def format_custom_text():
469469
])
470470
for i in bar(range(25)):
471471
format_custom_text.update_mapping(eggs=i * 2)
472-
time.sleep(0.1)
472+
sleep(0.1)
473473

474474

475475
@example

‎progressbar/__about__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
long running operations.
2020
'''.strip().split())
2121
__email__ = 'wolph@wol.ph'
22-
__version__ = '3.17.1'
22+
__version__ = '3.18.0'
2323
__license__ = 'BSD'
2424
__copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)'
2525
__url__ = 'https://github.com/WoLpH/python-progressbar'

‎progressbar/bar.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ def update(self, value=None, force=False, **kwargs):
525525
self.start()
526526
return self.update(value, force=force, **kwargs)
527527

528-
current_time = time.time()
529528
minimum_update_interval = self._MINIMUM_UPDATE_INTERVAL
530-
if current_time - self._last_update_time < minimum_update_interval:
529+
update_delta = time.time() - self._last_update_time
530+
if update_delta < minimum_update_interval and not force:
531531
# Prevent updating too often
532532
return
533533

@@ -611,7 +611,7 @@ def finish(self):
611611
'Puts the ProgressBar bar in the finished state.'
612612

613613
self.end_time = datetime.now()
614-
self.update(self.max_value)
614+
self.update(self.max_value, force=True)
615615

616616
StdRedirectMixin.finish(self)
617617
ResizableMixin.finish(self)

‎tests/conftest.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import progressbar
23
import logging
34

@@ -14,7 +15,10 @@ def pytest_configure(config):
1415
logging.basicConfig(
1516
level=LOG_LEVELS.get(config.option.verbose, logging.DEBUG))
1617

17-
# Remove the update limit for tests by default
18-
progressbar.ProgressBar._MINIMUM_UPDATE_INTERVAL = 0.000001
1918

19+
@pytest.fixture(autouse=True)
20+
def small_interval(monkeypatch):
21+
# Remove the update limit for tests by default
22+
monkeypatch.setattr(
23+
progressbar.ProgressBar, '_MINIMUM_UPDATE_INTERVAL', 0.000001)
2024

File renamed without changes.
File renamed without changes.

‎tests/test_end.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import pytest
12
import progressbar
23

34

5+
@pytest.fixture(autouse=True)
6+
def large_interval(monkeypatch):
7+
# Remove the update limit for tests by default
8+
monkeypatch.setattr(
9+
progressbar.ProgressBar, '_MINIMUM_UPDATE_INTERVAL', 0.1)
10+
11+
412
def test_end():
513
m = 24514315
614
p = progressbar.ProgressBar(
@@ -11,13 +19,19 @@ def test_end():
1119
for x in range(0, m, 8192):
1220
p.update(x)
1321

22+
data = p.data()
23+
assert data['percentage'] < 100.
24+
1425
p.finish()
26+
1527
data = p.data()
1628
assert data['percentage'] >= 100.
29+
1730
assert p.value == m
1831

1932

20-
def test_end_100():
33+
def test_end_100(monkeypatch):
34+
progressbar.ProgressBar._MINIMUM_UPDATE_INTERVAL = 0.1
2135
p = progressbar.ProgressBar(
2236
widgets=[progressbar.Percentage(), progressbar.Bar()],
2337
max_value=101,
@@ -27,7 +41,10 @@ def test_end_100():
2741
p.update(x)
2842

2943
data = p.data()
30-
assert data['percentage'] >= 100.
44+
assert data['percentage'] < 100.
45+
3146
p.finish()
47+
48+
data = p.data()
3249
assert data['percentage'] >= 100.
3350

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL