1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2008, 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
34
33
from bzrlib.symbol_versioning import (
37
from bzrlib.tests import (
36
from bzrlib.tests import test_progress
41
37
from bzrlib.ui import text as _mod_ui_text
44
class TestUIConfiguration(tests.TestCaseWithTransport):
46
def test_output_encoding_configuration(self):
47
enc = fixtures.generate_unicode_encodings().next()
48
config.GlobalConfig().set_user_option('output_encoding',
50
ui = tests.TestUIFactory(stdin=None,
51
stdout=tests.StringIOWrapper(),
52
stderr=tests.StringIOWrapper())
53
os = ui.make_output_stream()
54
self.assertEquals(os.encoding, enc)
57
40
class TestTextUIFactory(tests.TestCase):
59
42
def test_text_factory_ascii_password(self):
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$')
103
131
def test_text_ui_get_boolean(self):
104
132
stdin = tests.StringIOWrapper("y\n" # True
160
187
factory.get_boolean,
161
188
"what do you want"))
162
189
output = out.getvalue()
163
self.assertContainsRe(output,
165
self.assertContainsRe(output,
190
self.assertContainsRe(factory.stdout.getvalue(),
192
self.assertContainsRe(factory.stdout.getvalue(),
166
193
r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
167
194
# stdin should have been totally consumed
168
195
self.assertEqual('', factory.stdin.readline())
359
386
def test_test_ui_factory_progress(self):
360
387
# there's no output; we just want to make sure this doesn't crash -
361
# see https://bugs.launchpad.net/bzr/+bug/408201
388
# see https://bugs.edge.launchpad.net/bzr/+bug/408201
362
389
ui = tests.TestUIFactory()
363
390
pb = ui.nested_progress_bar()
364
391
pb.update('hello')