bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3948.2.6
by Martin Pool
ProgressBarStack is deprecated |
1 |
# Copyright (C) 2005, 2008, 2009 Canonical Ltd
|
|
1185.49.22
by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1185.49.22
by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py |
16 |
|
17 |
"""Tests for the bzrlib ui
|
|
18 |
"""
|
|
19 |
||
20 |
import os |
|
|
1534.5.6
by Robert Collins
split out converter logic into per-format objects. |
21 |
from StringIO import StringIO |
|
1704.2.9
by Martin Pool
Make text_factory test not depend on 80-col terminal |
22 |
import re |
|
1185.49.22
by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py |
23 |
import sys |
|
4017.1.1
by John Arbash Meinel
Get a pb.tick() to work after calling pb.update() |
24 |
import time |
|
1185.49.22
by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py |
25 |
|
|
4488.1.1
by Vincent Ladeuil
(vila) Cleanup imports in some test files |
26 |
from bzrlib import ( |
27 |
errors, |
|
28 |
tests, |
|
29 |
ui as _mod_ui, |
|
|
4449.3.4
by Martin Pool
ProgressTask now talks to ProgressView; easier to test |
30 |
)
|
|
3948.2.6
by Martin Pool
ProgressBarStack is deprecated |
31 |
from bzrlib.symbol_versioning import ( |
32 |
deprecated_in, |
|
33 |
)
|
|
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
34 |
from bzrlib.tests import ( |
|
2363.4.10
by Vincent Ladeuil
Complete tests. |
35 |
TestCase, |
|
2294.4.4
by Vincent Ladeuil
Provide a better implementation for testing passwords. |
36 |
TestUIFactory, |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
37 |
StringIOWrapper, |
38 |
)
|
|
|
4449.3.4
by Martin Pool
ProgressTask now talks to ProgressView; easier to test |
39 |
from bzrlib.tests.test_progress import ( |
40 |
_NonTTYStringIO, |
|
41 |
_TTYStringIO, |
|
42 |
)
|
|
|
2363.4.10
by Vincent Ladeuil
Complete tests. |
43 |
from bzrlib.ui import ( |
|
4449.3.42
by Martin Pool
Add basic test for CannedInputUIFactory |
44 |
CannedInputUIFactory, |
|
2363.4.10
by Vincent Ladeuil
Complete tests. |
45 |
SilentUIFactory, |
|
4449.3.18
by Martin Pool
Fuse CLIUIFactory and TextUIFactory and deprecate the old name |
46 |
UIFactory, |
|
4449.3.14
by Martin Pool
Clean up pb tests into tabular form |
47 |
make_ui_for_terminal, |
|
2363.4.10
by Vincent Ladeuil
Complete tests. |
48 |
)
|
|
4110.2.15
by Martin Pool
Fix bug in showing task progress and add a test |
49 |
from bzrlib.ui.text import ( |
|
4449.2.4
by Martin Pool
Add tests for BZR_PROGRESS_BAR |
50 |
NullProgressView, |
|
4110.2.15
by Martin Pool
Fix bug in showing task progress and add a test |
51 |
TextProgressView, |
52 |
TextUIFactory, |
|
|
4792.8.1
by Martin Pool
Add TextUIOutputStream coordinated with progress view |
53 |
TextUIOutputStream, |
|
4110.2.15
by Martin Pool
Fix bug in showing task progress and add a test |
54 |
)
|
|
1185.49.22
by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py |
55 |
|
|
1681.1.2
by Robert Collins
* bzrlib.ui.text.TextUIFactory now accepts a bar_type parameter which |
56 |
|
|
4711.1.6
by Martin Pool
Separate TextUIFactory tests |
57 |
class TestTextUIFactory(tests.TestCase): |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
58 |
|
59 |
def test_text_factory_ascii_password(self): |
|
|
4488.1.1
by Vincent Ladeuil
(vila) Cleanup imports in some test files |
60 |
ui = tests.TestUIFactory(stdin='secret\n', |
61 |
stdout=tests.StringIOWrapper(), |
|
62 |
stderr=tests.StringIOWrapper()) |
|
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
63 |
pb = ui.nested_progress_bar() |
64 |
try: |
|
65 |
self.assertEqual('secret', |
|
66 |
self.apply_redirected(ui.stdin, ui.stdout, |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
67 |
ui.stderr, |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
68 |
ui.get_password)) |
69 |
# ': ' is appended to prompt
|
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
70 |
self.assertEqual(': ', ui.stderr.getvalue()) |
71 |
self.assertEqual('', ui.stdout.readline()) |
|
|
2363.4.3
by Vincent Ladeuil
Tidy-up tests. |
72 |
# stdin should be empty
|
|
2363.4.6
by Vincent Ladeuil
Fix tests around stdin emptyness. |
73 |
self.assertEqual('', ui.stdin.readline()) |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
74 |
finally: |
75 |
pb.finished() |
|
76 |
||
77 |
def test_text_factory_utf8_password(self): |
|
78 |
"""Test an utf8 password. |
|
79 |
||
80 |
We can't predict what encoding users will have for stdin, so we force
|
|
81 |
it to utf8 to test that we transport the password correctly.
|
|
82 |
"""
|
|
|
4488.1.1
by Vincent Ladeuil
(vila) Cleanup imports in some test files |
83 |
ui = tests.TestUIFactory(stdin=u'baz\u1234'.encode('utf8'), |
84 |
stdout=tests.StringIOWrapper(), |
|
85 |
stderr=tests.StringIOWrapper()) |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
86 |
ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8' |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
87 |
pb = ui.nested_progress_bar() |
88 |
try: |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
89 |
password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr, |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
90 |
ui.get_password, |
91 |
u'Hello \u1234 %(user)s', |
|
92 |
user=u'some\u1234') |
|
93 |
# We use StringIO objects, we need to decode them
|
|
94 |
self.assertEqual(u'baz\u1234', password.decode('utf8')) |
|
95 |
self.assertEqual(u'Hello \u1234 some\u1234: ', |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
96 |
ui.stderr.getvalue().decode('utf8')) |
97 |
# stdin and stdout should be empty
|
|
|
2363.4.6
by Vincent Ladeuil
Fix tests around stdin emptyness. |
98 |
self.assertEqual('', ui.stdin.readline()) |
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
99 |
self.assertEqual('', ui.stdout.readline()) |
|
2294.4.1
by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests. |
100 |
finally: |
101 |
pb.finished() |
|
|
1534.5.6
by Robert Collins
split out converter logic into per-format objects. |
102 |
|
103 |
def test_progress_note(self): |
|
104 |
stderr = StringIO() |
|
105 |
stdout = StringIO() |
|
|
3882.8.11
by Martin Pool
Choose the UIFactory class depending on the terminal capabilities |
106 |
ui_factory = TextUIFactory(stdin=StringIO(''), |
107 |
stderr=stderr, |
|
108 |
stdout=stdout) |
|
|
1558.8.5
by Aaron Bentley
Pass note up the stack instead of using bzrlib.ui_factory |
109 |
pb = ui_factory.nested_progress_bar() |
|
1558.8.4
by Aaron Bentley
Fixed test case for pb.note |
110 |
try: |
|
4712.1.3
by Martin Pool
Update deprecation version |
111 |
result = self.applyDeprecated(deprecated_in((2, 1, 0)), |
|
4471.2.2
by Martin Pool
Deprecate ProgressTask.note |
112 |
pb.note, |
113 |
't') |
|
|
1558.8.4
by Aaron Bentley
Fixed test case for pb.note |
114 |
self.assertEqual(None, result) |
115 |
self.assertEqual("t\n", stdout.getvalue()) |
|
|
1843.3.2
by John Arbash Meinel
Fix a ui test that depended on clearing |
116 |
# Since there was no update() call, there should be no clear() call
|
|
2363.4.4
by Vincent Ladeuil
More tidying-up. |
117 |
self.failIf(re.search(r'^\r {10,}\r$', |
118 |
stderr.getvalue()) is not None, |
|
|
1843.3.2
by John Arbash Meinel
Fix a ui test that depended on clearing |
119 |
'We cleared the stderr without anything to put there') |
120 |
finally: |
|
121 |
pb.finished() |
|
122 |
||
123 |
def test_progress_note_clears(self): |
|
|
4449.3.4
by Martin Pool
ProgressTask now talks to ProgressView; easier to test |
124 |
stderr = _TTYStringIO() |
125 |
stdout = _TTYStringIO() |
|
126 |
# so that we get a TextProgressBar
|
|
127 |
os.environ['TERM'] = 'xterm' |
|
|
3882.8.8
by Martin Pool
Progress and UI test cleanups |
128 |
ui_factory = TextUIFactory( |
|
3882.8.11
by Martin Pool
Choose the UIFactory class depending on the terminal capabilities |
129 |
stdin=StringIO(''), |
|
3882.8.4
by Martin Pool
All UI factories should support note() |
130 |
stdout=stdout, stderr=stderr) |
|
4449.3.4
by Martin Pool
ProgressTask now talks to ProgressView; easier to test |
131 |
self.assertIsInstance(ui_factory._progress_view, |
132 |
TextProgressView) |
|
|
1843.3.2
by John Arbash Meinel
Fix a ui test that depended on clearing |
133 |
pb = ui_factory.nested_progress_bar() |
134 |
try: |
|
135 |
# Create a progress update that isn't throttled
|
|
136 |
pb.update('x', 1, 1) |
|
|
4712.1.4
by Martin Pool
One more deprecation |
137 |
result = self.applyDeprecated(deprecated_in((2, 1, 0)), |
|
4471.2.2
by Martin Pool
Deprecate ProgressTask.note |
138 |
pb.note, 't') |
|
1843.3.2
by John Arbash Meinel
Fix a ui test that depended on clearing |
139 |
self.assertEqual(None, result) |
140 |
self.assertEqual("t\n", stdout.getvalue()) |
|
|
1558.8.4
by Aaron Bentley
Fixed test case for pb.note |
141 |
# the exact contents will depend on the terminal width and we don't
|
142 |
# care about that right now - but you're probably running it on at
|
|
143 |
# least a 10-character wide terminal :)
|
|
|
1843.3.2
by John Arbash Meinel
Fix a ui test that depended on clearing |
144 |
self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$') |
|
1558.8.4
by Aaron Bentley
Fixed test case for pb.note |
145 |
finally: |
|
1558.8.5
by Aaron Bentley
Pass note up the stack instead of using bzrlib.ui_factory |
146 |
pb.finished() |
|
1594.1.1
by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar. |
147 |
|
148 |
def test_progress_nested(self): |
|
149 |
# test factory based nested and popping.
|
|
|
3882.8.11
by Martin Pool
Choose the UIFactory class depending on the terminal capabilities |
150 |
ui = TextUIFactory(None, None, None) |
|
1594.1.1
by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar. |
151 |
pb1 = ui.nested_progress_bar() |
152 |
pb2 = ui.nested_progress_bar() |
|
|
3948.2.2
by Martin Pool
Corrections to finishing progress bars |
153 |
# You do get a warning if the outermost progress bar wasn't finished
|
154 |
# first - it's not clear if this is really useful or if it should just
|
|
155 |
# become orphaned -- mbp 20090120
|
|
|
3882.8.12
by Martin Pool
Give a warning, not an error, if a progress bar is not finished in order |
156 |
warnings, _ = self.callCatchWarnings(pb1.finished) |
|
3948.2.2
by Martin Pool
Corrections to finishing progress bars |
157 |
if len(warnings) != 1: |
158 |
self.fail("unexpected warnings: %r" % (warnings,)) |
|
|
1594.1.1
by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar. |
159 |
pb2.finished() |
160 |
pb1.finished() |
|
161 |
||
|
4449.3.38
by Martin Pool
Cleanup get_boolean tests |
162 |
def test_text_ui_get_boolean(self): |
|
4449.3.44
by Martin Pool
merge trunk |
163 |
stdin = StringIO("y\n" # True |
164 |
"n\n" # False |
|
165 |
"yes with garbage\nY\n" # True |
|
166 |
"not an answer\nno\n" # False |
|
167 |
"I'm sure!\nyes\n" # True |
|
168 |
"NO\n" # False |
|
169 |
"foo\n") |
|
|
4449.3.38
by Martin Pool
Cleanup get_boolean tests |
170 |
stdout = StringIO() |
171 |
stderr = StringIO() |
|
172 |
factory = TextUIFactory(stdin, stdout, stderr) |
|
|
1687.1.4
by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean(). |
173 |
self.assertEqual(True, factory.get_boolean("")) |
|
4503.2.5
by Vincent Ladeuil
ui.get_boolean can also use bool_from_string. |
174 |
self.assertEqual(False, factory.get_boolean("")) |
175 |
self.assertEqual(True, factory.get_boolean("")) |
|
176 |
self.assertEqual(False, factory.get_boolean("")) |
|
177 |
self.assertEqual(True, factory.get_boolean("")) |
|
178 |
self.assertEqual(False, factory.get_boolean("")) |
|
|
1687.1.4
by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean(). |
179 |
self.assertEqual("foo\n", factory.stdin.read()) |
|
2363.4.4
by Vincent Ladeuil
More tidying-up. |
180 |
# stdin should be empty
|
|
2363.4.6
by Vincent Ladeuil
Fix tests around stdin emptyness. |
181 |
self.assertEqual('', factory.stdin.readline()) |
|
1687.1.4
by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean(). |
182 |
|
|
4300.3.1
by Martin Pool
Fix string expansion in TextUIFactory.prompt |
183 |
def test_text_factory_prompt(self): |
184 |
# see <https://launchpad.net/bugs/365891>
|
|
|
4449.3.18
by Martin Pool
Fuse CLIUIFactory and TextUIFactory and deprecate the old name |
185 |
factory = TextUIFactory(StringIO(), StringIO(), StringIO()) |
|
4300.3.1
by Martin Pool
Fix string expansion in TextUIFactory.prompt |
186 |
factory.prompt('foo %2e') |
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
187 |
self.assertEqual('', factory.stdout.getvalue()) |
188 |
self.assertEqual('foo %2e', factory.stderr.getvalue()) |
|
|
4300.3.1
by Martin Pool
Fix string expansion in TextUIFactory.prompt |
189 |
|
|
1687.1.4
by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean(). |
190 |
def test_text_factory_prompts_and_clears(self): |
191 |
# a get_boolean call should clear the pb before prompting
|
|
|
3882.8.10
by Martin Pool
Fix up test_ui for new progress bars |
192 |
out = _TTYStringIO() |
|
4449.3.4
by Martin Pool
ProgressTask now talks to ProgressView; easier to test |
193 |
os.environ['TERM'] = 'xterm' |
|
3882.8.11
by Martin Pool
Choose the UIFactory class depending on the terminal capabilities |
194 |
factory = TextUIFactory(stdin=StringIO("yada\ny\n"), stdout=out, stderr=out) |
|
3882.8.10
by Martin Pool
Fix up test_ui for new progress bars |
195 |
pb = factory.nested_progress_bar() |
196 |
pb.show_bar = False |
|
197 |
pb.show_spinner = False |
|
198 |
pb.show_count = False |
|
199 |
pb.update("foo", 0, 1) |
|
|
2363.4.4
by Vincent Ladeuil
More tidying-up. |
200 |
self.assertEqual(True, |
201 |
self.apply_redirected(None, factory.stdout, |
|
202 |
factory.stdout, |
|
203 |
factory.get_boolean, |
|
204 |
"what do you want")) |
|
|
3882.8.10
by Martin Pool
Fix up test_ui for new progress bars |
205 |
output = out.getvalue() |
206 |
self.assertContainsRe(factory.stdout.getvalue(), |
|
207 |
"foo *\r\r *\r*") |
|
208 |
self.assertContainsRe(factory.stdout.getvalue(), |
|
209 |
r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ") |
|
210 |
# stdin should have been totally consumed
|
|
|
2363.4.6
by Vincent Ladeuil
Fix tests around stdin emptyness. |
211 |
self.assertEqual('', factory.stdin.readline()) |
|
4017.1.1
by John Arbash Meinel
Get a pb.tick() to work after calling pb.update() |
212 |
|
213 |
def test_text_tick_after_update(self): |
|
214 |
ui_factory = TextUIFactory(stdout=StringIO(), stderr=StringIO()) |
|
215 |
pb = ui_factory.nested_progress_bar() |
|
216 |
try: |
|
217 |
pb.update('task', 0, 3) |
|
218 |
# Reset the clock, so that it actually tries to repaint itself
|
|
219 |
ui_factory._progress_view._last_repaint = time.time() - 1.0 |
|
220 |
pb.tick() |
|
221 |
finally: |
|
222 |
pb.finished() |
|
|
4110.2.15
by Martin Pool
Fix bug in showing task progress and add a test |
223 |
|
|
4222.2.1
by Jelmer Vernooij
Add get_username() call to the UIFactory. |
224 |
def test_text_ui_getusername(self): |
225 |
factory = TextUIFactory(None, None, None) |
|
226 |
factory.stdin = StringIO("someuser\n\n") |
|
227 |
factory.stdout = StringIO() |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
228 |
factory.stderr = StringIO() |
|
4222.2.6
by Jelmer Vernooij
Remove use of NotATerminal. |
229 |
factory.stdout.encoding = "utf8" |
|
4222.2.1
by Jelmer Vernooij
Add get_username() call to the UIFactory. |
230 |
# there is no output from the base factory
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
231 |
self.assertEqual("someuser", |
232 |
factory.get_username('Hello %(host)s', host='some')) |
|
233 |
self.assertEquals("Hello some: ", factory.stderr.getvalue()) |
|
234 |
self.assertEquals('', factory.stdout.getvalue()) |
|
|
4222.2.1
by Jelmer Vernooij
Add get_username() call to the UIFactory. |
235 |
self.assertEqual("", factory.get_username("Gebruiker")) |
236 |
# stdin should be empty
|
|
237 |
self.assertEqual('', factory.stdin.readline()) |
|
238 |
||
|
4222.2.2
by Jelmer Vernooij
Review from vila: Deal with UTF8 strings in prompts, fix typo. |
239 |
def test_text_ui_getusername_utf8(self): |
|
4488.1.1
by Vincent Ladeuil
(vila) Cleanup imports in some test files |
240 |
ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'), |
241 |
stdout=tests.StringIOWrapper(), |
|
242 |
stderr=tests.StringIOWrapper()) |
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
243 |
ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8" |
|
4222.2.3
by Jelmer Vernooij
Also check for unicode usernames. |
244 |
pb = ui.nested_progress_bar() |
245 |
try: |
|
246 |
# there is no output from the base factory
|
|
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
247 |
username = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr, |
|
4222.2.12
by Jelmer Vernooij
Redirect to fix utf8 test with LC_ALL=C. |
248 |
ui.get_username, u'Hello\u1234 %(host)s', host=u'some\u1234') |
|
4222.2.8
by Jelmer Vernooij
Fix copy-n-paste error. |
249 |
self.assertEquals(u"someuser\u1234", username.decode('utf8')) |
|
4368.3.1
by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582. |
250 |
self.assertEquals(u"Hello\u1234 some\u1234: ", |
251 |
ui.stderr.getvalue().decode("utf8")) |
|
252 |
self.assertEquals('', ui.stdout.getvalue()) |
|
|
4222.2.3
by Jelmer Vernooij
Also check for unicode usernames. |
253 |
finally: |
254 |
pb.finished() |
|
|
4222.2.2
by Jelmer Vernooij
Review from vila: Deal with UTF8 strings in prompts, fix typo. |
255 |
|
|
4110.2.15
by Martin Pool
Fix bug in showing task progress and add a test |
256 |
|
|
4792.8.1
by Martin Pool
Add TextUIOutputStream coordinated with progress view |
257 |
class TestTextUIOutputStream(TestCase): |
258 |
"""Tests for output stream that synchronizes with progress bar.""" |
|
259 |
||
260 |
def test_output_clears_terminal(self): |
|
261 |
stdout = StringIO() |
|
262 |
stderr = StringIO() |
|
263 |
clear_calls = [] |
|
264 |
||
265 |
uif = TextUIFactory(None, stdout, stderr) |
|
266 |
uif.clear_term = lambda: clear_calls.append('clear') |
|
267 |
||
268 |
stream = TextUIOutputStream(uif, uif.stdout) |
|
269 |
stream.write("Hello world!\n") |
|
270 |
stream.write("there's more...\n") |
|
|
4792.8.3
by Martin Pool
Add TextUIOutputStream.writelines |
271 |
stream.writelines(["1\n", "2\n", "3\n"]) |
|
4792.8.1
by Martin Pool
Add TextUIOutputStream coordinated with progress view |
272 |
|
273 |
self.assertEqual(stdout.getvalue(), |
|
274 |
"Hello world!\n" |
|
|
4792.8.3
by Martin Pool
Add TextUIOutputStream.writelines |
275 |
"there's more...\n" |
276 |
"1\n2\n3\n") |
|
277 |
self.assertEqual(['clear', 'clear', 'clear'], |
|
|
4792.8.1
by Martin Pool
Add TextUIOutputStream coordinated with progress view |
278 |
clear_calls) |
279 |
||
280 |
||
281 |
||
|
4711.1.6
by Martin Pool
Separate TextUIFactory tests |
282 |
class UITests(tests.TestCase): |
283 |
||
284 |
def test_progress_construction(self): |
|
285 |
"""TextUIFactory constructs the right progress view. |
|
286 |
"""
|
|
287 |
for (file_class, term, pb, expected_pb_class) in ( |
|
288 |
# on an xterm, either use them or not as the user requests,
|
|
289 |
# otherwise default on
|
|
290 |
(_TTYStringIO, 'xterm', 'none', NullProgressView), |
|
291 |
(_TTYStringIO, 'xterm', 'text', TextProgressView), |
|
292 |
(_TTYStringIO, 'xterm', None, TextProgressView), |
|
293 |
# on a dumb terminal, again if there's explicit configuration do
|
|
294 |
# it, otherwise default off
|
|
295 |
(_TTYStringIO, 'dumb', 'none', NullProgressView), |
|
296 |
(_TTYStringIO, 'dumb', 'text', TextProgressView), |
|
297 |
(_TTYStringIO, 'dumb', None, NullProgressView), |
|
298 |
# on a non-tty terminal, it's null regardless of $TERM
|
|
299 |
(StringIO, 'xterm', None, NullProgressView), |
|
300 |
(StringIO, 'dumb', None, NullProgressView), |
|
301 |
# however, it can still be forced on
|
|
302 |
(StringIO, 'dumb', 'text', TextProgressView), |
|
303 |
):
|
|
304 |
os.environ['TERM'] = term |
|
305 |
if pb is None: |
|
306 |
if 'BZR_PROGRESS_BAR' in os.environ: |
|
307 |
del os.environ['BZR_PROGRESS_BAR'] |
|
308 |
else: |
|
309 |
os.environ['BZR_PROGRESS_BAR'] = pb |
|
310 |
stdin = file_class('') |
|
311 |
stderr = file_class() |
|
312 |
stdout = file_class() |
|
313 |
uif = make_ui_for_terminal(stdin, stdout, stderr) |
|
314 |
self.assertIsInstance(uif, TextUIFactory, |
|
315 |
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,)) |
|
316 |
self.assertIsInstance(uif.make_progress_view(), |
|
317 |
expected_pb_class, |
|
318 |
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,)) |
|
319 |
||
320 |
def test_text_ui_non_terminal(self): |
|
321 |
"""Even on non-ttys, make_ui_for_terminal gives a text ui.""" |
|
322 |
stdin = _NonTTYStringIO('') |
|
323 |
stderr = _NonTTYStringIO() |
|
324 |
stdout = _NonTTYStringIO() |
|
325 |
for term_type in ['dumb', None, 'xterm']: |
|
326 |
if term_type is None: |
|
327 |
del os.environ['TERM'] |
|
328 |
else: |
|
329 |
os.environ['TERM'] = term_type |
|
330 |
uif = make_ui_for_terminal(stdin, stdout, stderr) |
|
331 |
self.assertIsInstance(uif, TextUIFactory, |
|
332 |
'TERM=%r' % (term_type,)) |
|
333 |
||
334 |
||
|
4449.3.19
by Martin Pool
SilentUIFactory now always errors when asked for input |
335 |
class SilentUITests(TestCase): |
336 |
||
|
4449.3.36
by Martin Pool
Update tests: SilentUIFactory no longer does get_boolean or get_password |
337 |
def test_silent_factory_get_password(self): |
338 |
# A silent factory that can't do user interaction can't get a
|
|
339 |
# password. Possibly it should raise a more specific error but it
|
|
340 |
# can't succeed.
|
|
|
4449.3.19
by Martin Pool
SilentUIFactory now always errors when asked for input |
341 |
ui = SilentUIFactory() |
342 |
stdout = StringIO() |
|
343 |
self.assertRaises( |
|
344 |
NotImplementedError, |
|
345 |
self.apply_redirected, |
|
346 |
None, stdout, stdout, ui.get_password) |
|
347 |
# and it didn't write anything out either
|
|
348 |
self.assertEqual('', stdout.getvalue()) |
|
349 |
||
350 |
def test_silent_ui_getbool(self): |
|
351 |
factory = SilentUIFactory() |
|
352 |
stdout = StringIO() |
|
353 |
self.assertRaises( |
|
354 |
NotImplementedError, |
|
355 |
self.apply_redirected, |
|
356 |
None, stdout, stdout, factory.get_boolean, "foo") |
|
|
4449.3.42
by Martin Pool
Add basic test for CannedInputUIFactory |
357 |
|
358 |
||
|
4580.2.2
by Martin Pool
Add test for bug 408201 |
359 |
class TestUIFactoryTests(TestCase): |
360 |
||
361 |
def test_test_ui_factory_progress(self): |
|
362 |
# there's no output; we just want to make sure this doesn't crash -
|
|
363 |
# see https://bugs.edge.launchpad.net/bzr/+bug/408201
|
|
364 |
ui = TestUIFactory() |
|
365 |
pb = ui.nested_progress_bar() |
|
366 |
pb.update('hello') |
|
367 |
pb.tick() |
|
368 |
pb.finished() |
|
369 |
||
370 |
||
|
4449.3.42
by Martin Pool
Add basic test for CannedInputUIFactory |
371 |
class CannedInputUIFactoryTests(TestCase): |
372 |
||
373 |
def test_canned_input_get_input(self): |
|
374 |
uif = CannedInputUIFactory([True, 'mbp', 'password']) |
|
375 |
self.assertEqual(uif.get_boolean('Extra cheese?'), True) |
|
376 |
self.assertEqual(uif.get_username('Enter your user name'), 'mbp') |
|
377 |
self.assertEqual(uif.get_password('Password for %(host)s', host='example.com'), |
|
378 |
'password') |
|
|
4110.2.17
by Martin Pool
If one ProgressTask has no count, it passes through that of its child |
379 |
|
|
4503.2.1
by Vincent Ladeuil
Get a bool from a string. |
380 |
|
381 |
class TestBoolFromString(tests.TestCase): |
|
382 |
||
383 |
def assertIsTrue(self, s, accepted_values=None): |
|
384 |
res = _mod_ui.bool_from_string(s, accepted_values=accepted_values) |
|
385 |
self.assertEquals(True, res) |
|
386 |
||
387 |
def assertIsFalse(self, s, accepted_values=None): |
|
388 |
res = _mod_ui.bool_from_string(s, accepted_values=accepted_values) |
|
389 |
self.assertEquals(False, res) |
|
390 |
||
391 |
def assertIsNone(self, s, accepted_values=None): |
|
392 |
res = _mod_ui.bool_from_string(s, accepted_values=accepted_values) |
|
393 |
self.assertIs(None, res) |
|
394 |
||
395 |
def test_know_valid_values(self): |
|
396 |
self.assertIsTrue('true') |
|
397 |
self.assertIsFalse('false') |
|
398 |
self.assertIsTrue('1') |
|
399 |
self.assertIsFalse('0') |
|
400 |
self.assertIsTrue('on') |
|
401 |
self.assertIsFalse('off') |
|
402 |
self.assertIsTrue('yes') |
|
403 |
self.assertIsFalse('no') |
|
404 |
self.assertIsTrue('y') |
|
405 |
self.assertIsFalse('n') |
|
406 |
# Also try some case variations
|
|
407 |
self.assertIsTrue('True') |
|
408 |
self.assertIsFalse('False') |
|
409 |
self.assertIsTrue('On') |
|
410 |
self.assertIsFalse('Off') |
|
411 |
self.assertIsTrue('ON') |
|
412 |
self.assertIsFalse('OFF') |
|
413 |
self.assertIsTrue('oN') |
|
414 |
self.assertIsFalse('oFf') |
|
415 |
||
416 |
def test_invalid_values(self): |
|
417 |
self.assertIsNone(None) |
|
418 |
self.assertIsNone('doubt') |
|
419 |
self.assertIsNone('frue') |
|
420 |
self.assertIsNone('talse') |
|
421 |
self.assertIsNone('42') |
|
422 |
||
423 |
def test_provided_values(self): |
|
424 |
av = dict(y=True, n=False, yes=True, no=False) |
|
425 |
self.assertIsTrue('y', av) |
|
426 |
self.assertIsTrue('Y', av) |
|
427 |
self.assertIsTrue('Yes', av) |
|
428 |
self.assertIsFalse('n', av) |
|
429 |
self.assertIsFalse('N', av) |
|
430 |
self.assertIsFalse('No', av) |
|
431 |
self.assertIsNone('1', av) |
|
432 |
self.assertIsNone('0', av) |
|
433 |
self.assertIsNone('on', av) |
|
434 |
self.assertIsNone('off', av) |