258
class TestTextProgressView(TestCase):
259
"""Tests for text display of progress bars.
261
# XXX: These might be a bit easier to write if the rendering and
262
# state-maintaining parts of TextProgressView were more separate, and if
263
# the progress task called back directly to its own view not to the ui
264
# factory. -- mbp 20090312
266
def _make_factory(self):
268
uif = TextUIFactory(stderr=out)
269
uif._progress_view._width = 80
272
def test_render_progress_easy(self):
273
"""Just one task and one quarter done"""
274
out, uif = self._make_factory()
275
task = uif.nested_progress_bar()
276
task.update('reticulating splines', 5, 20)
278
'\r[####/ ] reticulating splines 5/20 \r'
281
def test_render_progress_nested(self):
282
"""Tasks proportionally contribute to overall progress"""
283
out, uif = self._make_factory()
284
task = uif.nested_progress_bar()
285
task.update('reticulating splines', 0, 2)
286
task2 = uif.nested_progress_bar()
287
task2.update('stage2', 1, 2)
288
# so we're in the first half of the main task, and half way through
291
r'[####\ ] reticulating splines:stage2 1/2'
292
, uif._progress_view._render_line())
293
# if the nested task is complete, then we're all the way through the
294
# first half of the overall work
295
task2.update('stage2', 2, 2)
297
r'[#########| ] reticulating splines:stage2 2/2'
298
, uif._progress_view._render_line())
300
def test_render_progress_sub_nested(self):
301
"""Intermediate tasks don't mess up calculation."""
302
out, uif = self._make_factory()
303
task_a = uif.nested_progress_bar()
304
task_a.update('a', 0, 2)
305
task_b = uif.nested_progress_bar()
307
task_c = uif.nested_progress_bar()
308
task_c.update('c', 1, 2)
309
# the top-level task is in its first half; the middle one has no
310
# progress indication, just a label; and the bottom one is half done,
311
# so the overall fraction is 1/4
313
r'[####| ] a:b:c 1/2'
314
, uif._progress_view._render_line())