We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b012105 commit badac1eCopy full SHA for badac1e
2 files changed
progressbar/bar.py
@@ -459,7 +459,7 @@ def __exit__(self, exc_type, exc_value, traceback):
459
self.finish()
460
461
def __enter__(self):
462
- return self.start()
+ return self
463
464
# Create an alias so that Python 2.x won't complain about not being
465
# an iterator.
tests/test_monitor_progress.py
@@ -1,3 +1,6 @@
1
+import six
2
+import time
3
+import progressbar
4
pytest_plugins = 'pytester'
5
6
@@ -89,3 +92,36 @@ def test_rapid_updates(testdir):
89
92
r' 91% \(91 of 100\)',
90
93
r'100% \(100 of 100\)'
91
94
])
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