Skip to content

Commit d7477d5

Browse files
committed
fixed all warnings
1 parent e5808f9 commit d7477d5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

progressbar/widgets.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,11 @@ def __call__(self, progress, data):
769769
context['precision'] = self.precision
770770

771771
try:
772-
context['formatted_value'] = '{value:{width}.{precision}}'.format(
773-
**context)
772+
# Make sure to try and cast the value first, otherwise the
773+
# formatting will generate warnings/errors on newer Python releases
774+
value = float(value)
775+
fmt = '{value:{width}.{precision}}'
776+
context['formatted_value'] = fmt.format(**context)
774777
except (TypeError, ValueError):
775778
if value:
776779
context['formatted_value'] = '{value:{width}}'.format(

tests/test_progressbar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_examples(monkeypatch):
1414
pass
1515

1616

17+
@pytest.mark.filterwarnings('ignore:.*maxval.*:DeprecationWarning')
1718
@pytest.mark.parametrize('example', original_examples.examples)
1819
def test_original_examples(example, monkeypatch):
1920
monkeypatch.setattr(progressbar.ProgressBar,
@@ -22,13 +23,12 @@ def test_original_examples(example, monkeypatch):
2223
example()
2324

2425

25-
def test_examples_nullbar(monkeypatch):
26+
@pytest.mark.parametrize('example', examples.examples)
27+
def test_examples_nullbar(monkeypatch, example):
2628
# Patch progressbar to use null bar instead of regular progress bar
2729
monkeypatch.setattr(progressbar, 'ProgressBar', progressbar.NullBar)
28-
2930
assert progressbar.ProgressBar._MINIMUM_UPDATE_INTERVAL < 0.0001
30-
for example in examples.examples:
31-
example()
31+
example()
3232

3333

3434
def test_reuse():

0 commit comments

Comments
 (0)