| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -459,7 +459,7 @@ def __exit__(self, exc_type, exc_value, traceback): | |||
| 459 | 459 | self.finish() | |
| 460 | 460 | ||
| 461 | 461 | def __enter__(self): | |
| 462 | - return self.start() | ||
| 462 | + return self | ||
| 463 | 463 | ||
| 464 | 464 | # Create an alias so that Python 2.x won't complain about not being | |
| 465 | 465 | # an iterator. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,6 @@ | |||
| 1 | + import six | ||
| 2 | + import time | ||
| 3 | + import progressbar | ||
| 1 | 4 | pytest_plugins = 'pytester' | |
| 2 | 5 | ||
| 3 | 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments