33
34
from bzrlib.symbol_versioning import (
36
from bzrlib.tests import test_progress
37
from bzrlib.tests import (
37
41
from bzrlib.ui import text as _mod_ui_text
42
from bzrlib.ui.testsupport import (
47
class TestUIConfiguration(tests.TestCaseWithTransport):
49
def test_output_encoding_configuration(self):
50
enc = fixtures.generate_unicode_encodings().next()
51
config.GlobalConfig().set_user_option('output_encoding',
53
ui = tests.TestUIFactory(stdin=None,
54
stdout=tests.StringIOWrapper(),
55
stderr=tests.StringIOWrapper())
56
os = ui.make_output_stream()
57
self.assertEquals(os.encoding, enc)
40
60
class TestTextUIFactory(tests.TestCase):
86
def test_progress_note(self):
87
stderr = tests.StringIOWrapper()
88
stdout = tests.StringIOWrapper()
89
ui_factory = _mod_ui_text.TextUIFactory(stdin=tests.StringIOWrapper(''),
92
pb = ui_factory.nested_progress_bar()
94
result = self.applyDeprecated(deprecated_in((2, 1, 0)),
97
self.assertEqual(None, result)
98
self.assertEqual("t\n", stdout.getvalue())
99
# Since there was no update() call, there should be no clear() call
100
self.failIf(re.search(r'^\r {10,}\r$',
101
stderr.getvalue()) is not None,
102
'We cleared the stderr without anything to put there')
106
def test_progress_note_clears(self):
107
stderr = test_progress._TTYStringIO()
108
stdout = test_progress._TTYStringIO()
109
# so that we get a TextProgressBar
110
os.environ['TERM'] = 'xterm'
111
ui_factory = _mod_ui_text.TextUIFactory(
112
stdin=tests.StringIOWrapper(''),
113
stdout=stdout, stderr=stderr)
114
self.assertIsInstance(ui_factory._progress_view,
115
_mod_ui_text.TextProgressView)
116
pb = ui_factory.nested_progress_bar()
118
# Create a progress update that isn't throttled
120
result = self.applyDeprecated(deprecated_in((2, 1, 0)),
122
self.assertEqual(None, result)
123
self.assertEqual("t\n", stdout.getvalue())
124
# the exact contents will depend on the terminal width and we don't
125
# care about that right now - but you're probably running it on at
126
# least a 10-character wide terminal :)
127
self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
131
106
def test_text_ui_get_boolean(self):
132
107
stdin = tests.StringIOWrapper("y\n" # True
187
163
factory.get_boolean,
188
164
"what do you want"))
189
165
output = out.getvalue()
190
self.assertContainsRe(factory.stdout.getvalue(),
192
self.assertContainsRe(factory.stdout.getvalue(),
166
self.assertContainsRe(output,
168
self.assertContainsRe(output,
193
169
r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
194
170
# stdin should have been totally consumed
195
171
self.assertEqual('', factory.stdin.readline())
386
362
def test_test_ui_factory_progress(self):
387
363
# there's no output; we just want to make sure this doesn't crash -
388
# see https://bugs.edge.launchpad.net/bzr/+bug/408201
364
# see https://bugs.launchpad.net/bzr/+bug/408201
389
365
ui = tests.TestUIFactory()
390
366
pb = ui.nested_progress_bar()
391
367
pb.update('hello')
459
435
self.assertIsNone('0', av)
460
436
self.assertIsNone('on', av)
461
437
self.assertIsNone('off', av)
440
class TestCapturingUI(tests.TestCase):
441
"""Test test-oriented UIFactory that records progress updates"""
443
def test_nested_ignore_depth_beyond_one(self):
444
# we only want to capture the first level out progress, not
445
# want sub-components might do. So we have nested bars ignored.
446
factory = CapturingUIFactory()
447
pb1 = factory.nested_progress_bar()
448
pb1.update('foo', 0, 1)
449
pb2 = factory.nested_progress_bar()
450
pb2.update('foo', 0, 1)
453
self.assertEqual([("update", 0, 1, 'foo')], factory._calls)