/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.progress import (
29
29
    DotsProgressBar,
30
30
    ProgressBarStack,
 
31
    ProgressTask,
31
32
    TTYProgressBar,
32
33
    )
33
34
from bzrlib.symbol_versioning import (
43
44
    CLIUIFactory,
44
45
    SilentUIFactory,
45
46
    )
46
 
from bzrlib.ui.text import TextUIFactory
 
47
from bzrlib.ui.text import (
 
48
    TextProgressView,
 
49
    TextUIFactory,
 
50
    )
47
51
 
48
52
 
49
53
class UITests(TestCase):
249
253
            pb.tick()
250
254
        finally:
251
255
            pb.finished()
 
256
 
 
257
 
 
258
class TestTextProgressView(TestCase):
 
259
    """Tests for text display of progress bars.
 
260
    """
 
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
 
265
    
 
266
    def _make_factory(self):
 
267
        out = StringIO()
 
268
        uif = TextUIFactory(stderr=out)
 
269
        uif._progress_view._width = 80
 
270
        return out, uif
 
271
 
 
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)
 
277
        self.assertEqual(
 
278
'\r[####/               ] reticulating splines 5/20                               \r'
 
279
            , out.getvalue())
 
280
 
 
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
 
289
        # that
 
290
        self.assertEqual(
 
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)
 
296
        self.assertEqual(
 
297
r'[#########|          ] reticulating splines:stage2 2/2'
 
298
            , uif._progress_view._render_line())
 
299
 
 
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()
 
306
        task_b.update('b')
 
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
 
312
        self.assertEqual(
 
313
            r'[####|               ] a:b:c 1/2'
 
314
            , uif._progress_view._render_line())
 
315