26
26
import bzrlib.errors as errors
27
27
from bzrlib.progress import TTYProgressBar, ProgressBarStack
28
28
from bzrlib.tests import TestCase
29
from bzrlib.tests.test_progress import _TTYStringIO
30
29
from bzrlib.ui import SilentUIFactory
31
30
from bzrlib.ui.text import TextUIFactory
64
63
def test_progress_note(self):
65
64
stderr = StringIO()
66
65
stdout = StringIO()
67
ui_factory = TextUIFactory(bar_type=TTYProgressBar)
68
pb = ui_factory.nested_progress_bar()
70
pb.to_messages_file = stdout
71
ui_factory._progress_bar_stack.bottom().to_file = stderr
73
self.assertEqual(None, result)
74
self.assertEqual("t\n", stdout.getvalue())
75
# Since there was no update() call, there should be no clear() call
76
self.failIf(re.search(r'^\r {10,}\r$', stderr.getvalue()) is not None,
77
'We cleared the stderr without anything to put there')
81
def test_progress_note_clears(self):
84
# The PQM redirects the output to a file, so it
85
# defaults to creating a Dots progress bar. we
86
# need to force it to believe we are a TTY
87
ui_factory = TextUIFactory(bar_type=TTYProgressBar)
88
pb = ui_factory.nested_progress_bar()
90
pb.to_messages_file = stdout
91
ui_factory._progress_bar_stack.bottom().to_file = stderr
92
# Create a progress update that isn't throttled
66
ui_factory = TextUIFactory()
67
pb = ui_factory.nested_progress_bar()
69
pb.to_messages_file = stdout
70
ui_factory._progress_bar_stack.bottom().to_file = stderr
95
71
result = pb.note('t')
96
72
self.assertEqual(None, result)
97
73
self.assertEqual("t\n", stdout.getvalue())
98
74
# the exact contents will depend on the terminal width and we don't
99
75
# care about that right now - but you're probably running it on at
100
76
# least a 10-character wide terminal :)
101
self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
77
self.assertContainsRe(stderr.getvalue(), r'^\r {10,}\r$')
177
153
def test_text_factory_prompts_and_clears(self):
178
154
# a get_boolean call should clear the pb before prompting
179
155
factory = bzrlib.ui.text.TextUIFactory()
180
factory.stdout = _TTYStringIO()
156
factory.stdout = StringIO()
181
157
factory.stdin = StringIO("yada\ny\n")
182
158
pb = self.apply_redirected(
183
159
factory.stdin, factory.stdout, factory.stdout, factory.nested_progress_bar)
185
160
self.apply_redirected(
186
161
factory.stdin, factory.stdout, factory.stdout, pb.update, "foo", 0, 1)
187
162
self.assertEqual(
199
174
"\rwhat do you want\\? \\[y/n\\]:what do you want\\? \\[y/n\\]:",
201
self.fail("didn't match factory output %r, %s" % (factory, output))
176
self.fail("didn't match factory output %r" % factory)