~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

Introduce new bzr progress bar api. ui_factory.nested_progress_bar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from StringIO import StringIO
22
22
import sys
23
23
 
24
 
from bzrlib.progress import TTYProgressBar
 
24
 
 
25
import bzrlib.errors as errors
 
26
from bzrlib.progress import TTYProgressBar, ProgressBarStack
25
27
from bzrlib.tests import TestCase
26
28
from bzrlib.ui import SilentUIFactory
27
29
from bzrlib.ui.text import TextUIFactory
56
58
    def test_progress_note(self):
57
59
        stderr = StringIO()
58
60
        stdout = StringIO()
59
 
        ui = TextUIFactory()
60
61
        pb = TTYProgressBar(to_file=stderr, to_messages_file=stdout)
61
62
        result = pb.note('t')
62
63
        self.assertEqual(None, result)
65
66
        # care about that right now - but you're probably running it on at
66
67
        # least a 10-character wide terminal :)
67
68
        self.assertContainsRe(stderr.getvalue(), r'^\r {10,}\r$')
 
69
 
 
70
    def test_progress_nested(self):
 
71
        # test factory based nested and popping.
 
72
        ui = TextUIFactory()
 
73
        pb1 = ui.nested_progress_bar()
 
74
        pb2 = ui.nested_progress_bar()
 
75
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
76
        pb2.finished()
 
77
        pb1.finished()
 
78
 
 
79
    def test_progress_stack(self):
 
80
        # test the progress bar stack which the default text factory 
 
81
        # uses.
 
82
        stderr = StringIO()
 
83
        stdout = StringIO()
 
84
        # make a stack, which accepts parameters like a pb.
 
85
        stack = ProgressBarStack(to_file=stderr, to_messages_file=stdout)
 
86
        # but is not one
 
87
        self.assertFalse(getattr(stack, 'note', False))
 
88
        pb1 = stack.get_nested()
 
89
        pb2 = stack.get_nested()
 
90
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
91
        pb2.finished()
 
92
        pb1.finished()
 
93
        # the text ui factory never actually removes the stack once its setup.
 
94
        # we need to be able to nest again correctly from here.
 
95
        pb1 = stack.get_nested()
 
96
        pb2 = stack.get_nested()
 
97
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
98
        pb2.finished()
 
99
        pb1.finished()