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

added tests for fix #92 and fixed #161 · rezanaima/python-progressbar@badac1e · GitHub

Commit badac1e

Browse files
committed
added tests for fix wolph#92 and fixed wolph#161
1 parent b012105 commit badac1e

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎progressbar/bar.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def __exit__(self, exc_type, exc_value, traceback):
459459
self.finish()
460460

461461
def __enter__(self):
462-
return self.start()
462+
return self
463463

464464
# Create an alias so that Python 2.x won't complain about not being
465465
# an iterator.

‎tests/test_monitor_progress.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import six
2+
import time
3+
import progressbar
14
pytest_plugins = 'pytester'
25

36

@@ -89,3 +92,36 @@ def test_rapid_updates(testdir):
8992
r' 91% \(91 of 100\)',
9093
r'100% \(100 of 100\)'
9194
])
95+
96+
97+
def test_context_wrapper(testdir):
98+
fd = six.StringIO()
99+
100+
with progressbar.ProgressBar(term_width=60, fd=fd) as bar:
101+
bar._MINIMUM_UPDATE_INTERVAL = 0.0001
102+
for _ in bar(range(5)):
103+
time.sleep(0.001)
104+
105+
expected = (
106+
'',
107+
' ',
108+
'',
109+
'N/A% (0 of 5) | | Elapsed Time: 0:00:00 ETA: --:--:--',
110+
' ',
111+
'',
112+
' 20% (1 of 5) |# | Elapsed Time: 0:00:00 ETA: 0:00:00',
113+
' ',
114+
'',
115+
' 40% (2 of 5) |### | Elapsed Time: 0:00:00 ETA: 0:00:00',
116+
' ',
117+
'',
118+
' 60% (3 of 5) |#### | Elapsed Time: 0:00:00 ETA: 0:00:00',
119+
' ',
120+
'',
121+
' 80% (4 of 5) |###### | Elapsed Time: 0:00:00 ETA: 0:00:00',
122+
' ',
123+
'',
124+
'100% (5 of 5) |########| Elapsed Time: 0:00:00 Time: 0:00:00',
125+
)
126+
for line, expected_line in zip(fd.getvalue().split('\r'), expected):
127+
assert line == expected_line

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL