| 1 |
import time |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| •5 |
import progressbar2 |
| 6 |
|
| 7 |
|
| 8 |
def test_list() -> None: |
| 9 |
"""Progressbar can guess max_value automatically.""" |
| •10 |
p = progressbar2.ProgressBar() |
| 11 |
for _i in p(range(10)): |
| 12 |
time.sleep(0.001) |
| 13 |
|
| 14 |
|
| 15 |
def test_iterator_with_max_value() -> None: |
| 16 |
"""Progressbar can't guess max_value.""" |
| •17 |
p = progressbar2.ProgressBar(max_value=10) |
| 18 |
for _i in p(iter(range(10))): |
| 19 |
time.sleep(0.001) |
| 20 |
|
| 21 |
|
| 22 |
def test_iterator_without_max_value_error() -> None: |
| 23 |
"""Progressbar can't guess max_value.""" |
| •24 |
p = progressbar2.ProgressBar() |
| 25 |
|
| 26 |
for _i in p(iter(range(10))): |
| 27 |
time.sleep(0.001) |
| 28 |
|
| •29 |
assert p.max_value is progressbar2.UnknownLength |
| 30 |
|
| 31 |
|
| 32 |
def test_iterator_without_max_value() -> None: |
| 33 |
"""Progressbar can't guess max_value.""" |
| •34 |
p = progressbar2.ProgressBar( |
| 35 |
widgets=[ |
| •36 |
progressbar2.AnimatedMarker(), |
| 37 |
progressbar2.FormatLabel('%(value)d'), |
| 38 |
progressbar2.BouncingBar(), |
| 39 |
progressbar2.BouncingBar(marker=progressbar2.RotatingMarker()), |
| 40 |
], |
| 41 |
) |
| 42 |
for _i in p(iter(range(10))): |
| 43 |
time.sleep(0.001) |
| 44 |
|
| 45 |
|
| 46 |
def test_iterator_with_incorrect_max_value() -> None: |
| 47 |
"""Progressbar can't guess max_value.""" |
| •48 |
p = progressbar2.ProgressBar(max_value=10) |
| 49 |
with pytest.raises(ValueError): |
| 50 |
for _i in p(iter(range(20))): |
| 51 |
time.sleep(0.001) |
| 52 |
|
| 53 |
|
| 54 |
def test_adding_value() -> None: |
| •55 |
p = progressbar2.ProgressBar(max_value=10) |
| 56 |
p.start() |
| 57 |
p.update(5) |
| 58 |
p += 2 |
| 59 |
p.increment(2) |
| 60 |
with pytest.raises(ValueError): |
| 61 |
p += 5 |