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