bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
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 version 2 as published by
|
|
5 |
# the Free Software Foundation.
|
|
6 |
#
|
|
7 |
# This program is distributed in the hope that it will be useful,
|
|
8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
# GNU General Public License for more details.
|
|
11 |
#
|
|
12 |
# You should have received a copy of the GNU General Public License
|
|
13 |
# along with this program; if not, write to the Free Software
|
|
14 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15 |
||
16 |
"""UI tests for the test framework."""
|
|
17 |
||
|
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
18 |
import os |
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
19 |
import signal |
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
20 |
import sys |
21 |
||
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
22 |
import bzrlib |
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
23 |
from bzrlib import ( |
24 |
osutils, |
|
25 |
)
|
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
26 |
from bzrlib.errors import ParamikoNotPresent |
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
27 |
from bzrlib.tests import ( |
28 |
TestCase, |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
29 |
TestCaseWithMemoryTransport, |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
30 |
TestCaseWithTransport, |
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
31 |
TestSkipped, |
32 |
)
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
33 |
from bzrlib.tests.blackbox import ExternalBase |
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
34 |
|
35 |
||
36 |
class TestOptions(TestCase): |
|
37 |
||
38 |
current_test = None |
|
39 |
||
40 |
def test_transport_set_to_sftp(self): |
|
41 |
# test the --transport option has taken effect from within the
|
|
42 |
# test_transport test
|
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
43 |
try: |
44 |
import bzrlib.transport.sftp |
|
45 |
except ParamikoNotPresent: |
|
46 |
raise TestSkipped("Paramiko not present") |
|
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
47 |
if TestOptions.current_test != "test_transport_set_to_sftp": |
48 |
return
|
|
49 |
self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer, |
|
50 |
bzrlib.tests.default_transport) |
|
51 |
||
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
52 |
def test_transport_set_to_memory(self): |
53 |
# test the --transport option has taken effect from within the
|
|
54 |
# test_transport test
|
|
55 |
import bzrlib.transport.memory |
|
56 |
if TestOptions.current_test != "test_transport_set_to_memory": |
|
57 |
return
|
|
58 |
self.assertEqual(bzrlib.transport.memory.MemoryServer, |
|
59 |
bzrlib.tests.default_transport) |
|
60 |
||
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
61 |
def test_transport(self): |
62 |
# test that --transport=sftp works
|
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
63 |
try: |
64 |
import bzrlib.transport.sftp |
|
65 |
except ParamikoNotPresent: |
|
66 |
raise TestSkipped("Paramiko not present") |
|
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
67 |
old_transport = bzrlib.tests.default_transport |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
68 |
old_root = TestCaseWithMemoryTransport.TEST_ROOT |
69 |
TestCaseWithMemoryTransport.TEST_ROOT = None |
|
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
70 |
try: |
71 |
TestOptions.current_test = "test_transport_set_to_sftp" |
|
72 |
stdout = self.capture('selftest --transport=sftp test_transport_set_to_sftp') |
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
73 |
|
74 |
self.assertContainsRe(stdout, 'Ran 1 test') |
|
75 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
76 |
||
77 |
TestOptions.current_test = "test_transport_set_to_memory" |
|
78 |
stdout = self.capture('selftest --transport=memory test_transport_set_to_memory') |
|
|
1534.4.25
by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite. |
79 |
self.assertContainsRe(stdout, 'Ran 1 test') |
80 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
81 |
finally: |
|
82 |
bzrlib.tests.default_transport = old_transport |
|
83 |
TestOptions.current_test = None |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
84 |
TestCaseWithMemoryTransport.TEST_ROOT = old_root |
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
85 |
|
86 |
||
87 |
class TestRunBzr(ExternalBase): |
|
88 |
||
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
89 |
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None, |
90 |
working_dir=None): |
|
|
2027.5.3
by John Arbash Meinel
Add docstring to why run_bzr_captured is overridden |
91 |
"""Override run_bzr_captured to test how it is invoked by run_bzr. |
92 |
||
93 |
We test how run_bzr_captured actually invokes bzr in another location.
|
|
94 |
Here we only need to test that it is run_bzr passes the right
|
|
95 |
parameters to run_bzr_captured.
|
|
96 |
"""
|
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
97 |
self.argv = argv |
98 |
self.retcode = retcode |
|
99 |
self.encoding = encoding |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
100 |
self.stdin = stdin |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
101 |
self.working_dir = working_dir |
102 |
||
103 |
def test_args(self): |
|
104 |
"""Test that run_bzr passes args correctly to run_bzr_captured""" |
|
105 |
self.run_bzr('arg1', 'arg2', 'arg3', retcode=1) |
|
106 |
self.assertEqual(('arg1', 'arg2', 'arg3'), self.argv) |
|
107 |
||
108 |
def test_encoding(self): |
|
109 |
"""Test that run_bzr passes encoding to run_bzr_captured""" |
|
110 |
self.run_bzr('foo', 'bar') |
|
111 |
self.assertEqual(None, self.encoding) |
|
112 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
113 |
||
114 |
self.run_bzr('foo', 'bar', encoding='baz') |
|
115 |
self.assertEqual('baz', self.encoding) |
|
116 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
117 |
||
118 |
def test_retcode(self): |
|
119 |
"""Test that run_bzr passes retcode to run_bzr_captured""" |
|
120 |
# Default is retcode == 0
|
|
121 |
self.run_bzr('foo', 'bar') |
|
122 |
self.assertEqual(0, self.retcode) |
|
123 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
124 |
||
125 |
self.run_bzr('foo', 'bar', retcode=1) |
|
126 |
self.assertEqual(1, self.retcode) |
|
127 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
128 |
||
129 |
self.run_bzr('foo', 'bar', retcode=None) |
|
130 |
self.assertEqual(None, self.retcode) |
|
131 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
132 |
||
133 |
self.run_bzr('foo', 'bar', retcode=3) |
|
134 |
self.assertEqual(3, self.retcode) |
|
135 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
136 |
|
137 |
def test_stdin(self): |
|
138 |
# test that the stdin keyword to run_bzr is passed through to
|
|
|
1687.1.15
by Robert Collins
Review comments. |
139 |
# run_bzr_captured as-is. We do this by overriding
|
140 |
# run_bzr_captured in this class, and then calling run_bzr,
|
|
141 |
# which is a convenience function for run_bzr_captured, so
|
|
142 |
# should invoke it.
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
143 |
self.run_bzr('foo', 'bar', stdin='gam') |
144 |
self.assertEqual('gam', self.stdin) |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
145 |
self.assertEqual(('foo', 'bar'), self.argv) |
146 |
||
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
147 |
self.run_bzr('foo', 'bar', stdin='zippy') |
148 |
self.assertEqual('zippy', self.stdin) |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
149 |
self.assertEqual(('foo', 'bar'), self.argv) |
150 |
||
151 |
def test_working_dir(self): |
|
152 |
"""Test that run_bzr passes working_dir to run_bzr_captured""" |
|
153 |
self.run_bzr('foo', 'bar') |
|
154 |
self.assertEqual(None, self.working_dir) |
|
155 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
156 |
||
157 |
self.run_bzr('foo', 'bar', working_dir='baz') |
|
158 |
self.assertEqual('baz', self.working_dir) |
|
159 |
self.assertEqual(('foo', 'bar'), self.argv) |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
160 |
|
161 |
||
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
162 |
class TestBenchmarkTests(TestCaseWithTransport): |
163 |
||
164 |
def test_benchmark_runs_benchmark_tests(self): |
|
165 |
"""bzr selftest --benchmark should not run the default test suite.""" |
|
166 |
# We test this by passing a regression test name to --benchmark, which
|
|
167 |
# should result in 0 rests run.
|
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
168 |
old_root = TestCaseWithMemoryTransport.TEST_ROOT |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
169 |
try: |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
170 |
TestCaseWithMemoryTransport.TEST_ROOT = None |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
171 |
out, err = self.run_bzr('selftest', '--benchmark', 'workingtree_implementations') |
172 |
finally: |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
173 |
TestCaseWithMemoryTransport.TEST_ROOT = old_root |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
174 |
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK') |
175 |
self.assertEqual( |
|
176 |
'running tests...\ntests passed\n', |
|
177 |
err) |
|
178 |
benchfile = open(".perf_history", "rt") |
|
179 |
try: |
|
180 |
lines = benchfile.readlines() |
|
181 |
finally: |
|
182 |
benchfile.close() |
|
183 |
self.assertEqual(1, len(lines)) |
|
184 |
self.assertContainsRe(lines[0], "--date [0-9.]+") |
|
185 |
||
186 |
||
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
187 |
class TestRunBzrCaptured(ExternalBase): |
188 |
||
189 |
def apply_redirected(self, stdin=None, stdout=None, stderr=None, |
|
190 |
a_callable=None, *args, **kwargs): |
|
191 |
self.stdin = stdin |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
192 |
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None) |
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
193 |
self.factory = bzrlib.ui.ui_factory |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
194 |
self.working_dir = osutils.getcwd() |
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
195 |
stdout.write('foo\n') |
196 |
stderr.write('bar\n') |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
197 |
return 0 |
198 |
||
199 |
def test_stdin(self): |
|
200 |
# test that the stdin keyword to run_bzr_captured is passed through to
|
|
|
1687.1.15
by Robert Collins
Review comments. |
201 |
# apply_redirected as a StringIO. We do this by overriding
|
202 |
# apply_redirected in this class, and then calling run_bzr_captured,
|
|
203 |
# which calls apply_redirected.
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
204 |
self.run_bzr_captured(['foo', 'bar'], stdin='gam') |
205 |
self.assertEqual('gam', self.stdin.read()) |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
206 |
self.assertTrue(self.stdin is self.factory_stdin) |
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
207 |
self.run_bzr_captured(['foo', 'bar'], stdin='zippy') |
208 |
self.assertEqual('zippy', self.stdin.read()) |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
209 |
self.assertTrue(self.stdin is self.factory_stdin) |
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
210 |
|
211 |
def test_ui_factory(self): |
|
212 |
# each invocation of self.run_bzr_captured should get its own UI
|
|
213 |
# factory, which is an instance of TestUIFactory, with stdout and
|
|
214 |
# stderr attached to the stdout and stderr of the invoked
|
|
215 |
# run_bzr_captured
|
|
216 |
current_factory = bzrlib.ui.ui_factory |
|
217 |
self.run_bzr_captured(['foo']) |
|
218 |
self.failIf(current_factory is self.factory) |
|
219 |
self.assertNotEqual(sys.stdout, self.factory.stdout) |
|
220 |
self.assertNotEqual(sys.stderr, self.factory.stderr) |
|
221 |
self.assertEqual('foo\n', self.factory.stdout.getvalue()) |
|
222 |
self.assertEqual('bar\n', self.factory.stderr.getvalue()) |
|
223 |
self.assertIsInstance(self.factory, bzrlib.tests.blackbox.TestUIFactory) |
|
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
224 |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
225 |
def test_working_dir(self): |
226 |
self.build_tree(['one/', 'two/']) |
|
227 |
cwd = osutils.getcwd() |
|
228 |
||
229 |
# Default is to work in the current directory
|
|
230 |
self.run_bzr_captured(['foo', 'bar']) |
|
231 |
self.assertEqual(cwd, self.working_dir) |
|
232 |
||
233 |
self.run_bzr_captured(['foo', 'bar'], working_dir=None) |
|
234 |
self.assertEqual(cwd, self.working_dir) |
|
235 |
||
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
236 |
# The function should be run in the alternative directory
|
237 |
# but afterwards the current working dir shouldn't be changed
|
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
238 |
self.run_bzr_captured(['foo', 'bar'], working_dir='one') |
239 |
self.assertNotEqual(cwd, self.working_dir) |
|
240 |
self.assertEndsWith(self.working_dir, 'one') |
|
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
241 |
self.assertEqual(cwd, osutils.getcwd()) |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
242 |
|
243 |
self.run_bzr_captured(['foo', 'bar'], working_dir='two') |
|
244 |
self.assertNotEqual(cwd, self.working_dir) |
|
245 |
self.assertEndsWith(self.working_dir, 'two') |
|
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
246 |
self.assertEqual(cwd, osutils.getcwd()) |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
247 |
|
248 |
||
249 |
class TestRunBzrSubprocess(TestCaseWithTransport): |
|
250 |
||
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
251 |
def test_run_bzr_subprocess(self): |
252 |
"""The run_bzr_helper_external comand behaves nicely.""" |
|
253 |
result = self.run_bzr_subprocess('--version') |
|
254 |
result = self.run_bzr_subprocess('--version', retcode=None) |
|
255 |
self.assertContainsRe(result[0], 'is free software') |
|
256 |
self.assertRaises(AssertionError, self.run_bzr_subprocess, |
|
257 |
'--versionn') |
|
258 |
result = self.run_bzr_subprocess('--versionn', retcode=3) |
|
259 |
result = self.run_bzr_subprocess('--versionn', retcode=None) |
|
260 |
self.assertContainsRe(result[1], 'unknown command') |
|
|
1857.1.20
by Aaron Bentley
Strip out all the EnumOption stuff |
261 |
err = self.run_bzr_subprocess('merge', '--merge-type', 'magic merge', |
262 |
retcode=3)[1] |
|
263 |
self.assertContainsRe(err, 'No known merge type magic merge') |
|
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
264 |
|
|
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
265 |
def test_run_bzr_subprocess_env(self): |
266 |
"""run_bzr_subprocess can set environment variables in the child only. |
|
267 |
||
268 |
These changes should not change the running process, only the child.
|
|
269 |
"""
|
|
270 |
# The test suite should unset this variable
|
|
271 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
272 |
out, err = self.run_bzr_subprocess('whoami', env_changes={ |
|
273 |
'BZR_EMAIL':'Joe Foo <joe@foo.com>' |
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
274 |
}, universal_newlines=True) |
|
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
275 |
self.assertEqual('', err) |
276 |
self.assertEqual('Joe Foo <joe@foo.com>\n', out) |
|
277 |
# And it should not be modified
|
|
278 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
279 |
||
280 |
# Do it again with a different address, just to make sure
|
|
281 |
# it is actually changing
|
|
282 |
out, err = self.run_bzr_subprocess('whoami', env_changes={ |
|
283 |
'BZR_EMAIL':'Barry <bar@foo.com>' |
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
284 |
}, universal_newlines=True) |
|
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
285 |
self.assertEqual('', err) |
286 |
self.assertEqual('Barry <bar@foo.com>\n', out) |
|
287 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
288 |
||
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
289 |
def test_run_bzr_subprocess_env_del(self): |
290 |
"""run_bzr_subprocess can remove environment variables too.""" |
|
291 |
# Create a random email, so we are sure this won't collide
|
|
292 |
rand_bzr_email = 'John Doe <jdoe@%s.com>' % (osutils.rand_chars(20),) |
|
293 |
rand_email = 'Jane Doe <jdoe@%s.com>' % (osutils.rand_chars(20),) |
|
294 |
os.environ['BZR_EMAIL'] = rand_bzr_email |
|
295 |
os.environ['EMAIL'] = rand_email |
|
296 |
try: |
|
297 |
# By default, the child will inherit the current env setting
|
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
298 |
out, err = self.run_bzr_subprocess('whoami', universal_newlines=True) |
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
299 |
self.assertEqual('', err) |
300 |
self.assertEqual(rand_bzr_email + '\n', out) |
|
301 |
||
302 |
# Now that BZR_EMAIL is not set, it should fall back to EMAIL
|
|
303 |
out, err = self.run_bzr_subprocess('whoami', |
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
304 |
env_changes={'BZR_EMAIL':None}, |
305 |
universal_newlines=True) |
|
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
306 |
self.assertEqual('', err) |
307 |
self.assertEqual(rand_email + '\n', out) |
|
308 |
||
309 |
# This switches back to the default email guessing logic
|
|
310 |
# Which shouldn't match either of the above addresses
|
|
311 |
out, err = self.run_bzr_subprocess('whoami', |
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
312 |
env_changes={'BZR_EMAIL':None, 'EMAIL':None}, |
313 |
universal_newlines=True) |
|
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
314 |
|
315 |
self.assertEqual('', err) |
|
316 |
self.assertNotEqual(rand_bzr_email + '\n', out) |
|
317 |
self.assertNotEqual(rand_email + '\n', out) |
|
318 |
finally: |
|
319 |
# TestCase cleans up BZR_EMAIL, and EMAIL at startup
|
|
320 |
del os.environ['BZR_EMAIL'] |
|
321 |
del os.environ['EMAIL'] |
|
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
322 |
|
|
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
323 |
def test_run_bzr_subprocess_env_del_missing(self): |
324 |
"""run_bzr_subprocess won't fail if deleting a nonexistant env var""" |
|
325 |
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ) |
|
326 |
out, err = self.run_bzr_subprocess('rocks', |
|
|
1963.1.11
by John Arbash Meinel
Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests |
327 |
env_changes={'NON_EXISTANT_ENV_VAR':None}, |
328 |
universal_newlines=True) |
|
329 |
self.assertEqual('it sure does!\n', out) |
|
330 |
self.assertEqual('', err) |
|
|
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
331 |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
332 |
def test_run_bzr_subprocess_working_dir(self): |
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
333 |
"""Test that we can specify the working dir for the child""" |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
334 |
cwd = osutils.getcwd() |
335 |
||
336 |
self.make_branch_and_tree('.') |
|
337 |
self.make_branch_and_tree('one') |
|
338 |
self.make_branch_and_tree('two') |
|
339 |
||
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
340 |
def get_root(**kwargs): |
341 |
"""Spawn a process to get the 'root' of the tree. |
|
342 |
||
343 |
You can pass in arbitrary new arguments. This just makes
|
|
344 |
sure that the returned path doesn't have trailing whitespace.
|
|
345 |
"""
|
|
346 |
return self.run_bzr_subprocess('root', **kwargs)[0].rstrip() |
|
347 |
||
348 |
self.assertEqual(cwd, get_root()) |
|
349 |
self.assertEqual(cwd, get_root(working_dir=None)) |
|
350 |
# Has our path changed?
|
|
351 |
self.assertEqual(cwd, osutils.getcwd()) |
|
352 |
||
353 |
dir1 = get_root(working_dir='one') |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
354 |
self.assertEndsWith(dir1, 'one') |
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
355 |
self.assertEqual(cwd, osutils.getcwd()) |
356 |
||
357 |
dir2 = get_root(working_dir='two') |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
358 |
self.assertEndsWith(dir2, 'two') |
|
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
359 |
self.assertEqual(cwd, osutils.getcwd()) |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
360 |
|
361 |
||
362 |
class TestBzrSubprocess(TestCaseWithTransport): |
|
363 |
||
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
364 |
def test_start_and_stop_bzr_subprocess(self): |
365 |
"""We can start and perform other test actions while that process is |
|
366 |
still alive.
|
|
367 |
"""
|
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
368 |
process = self.start_bzr_subprocess(['--version']) |
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
369 |
result = self.finish_bzr_subprocess(process) |
370 |
self.assertContainsRe(result[0], 'is free software') |
|
371 |
self.assertEqual('', result[1]) |
|
372 |
||
373 |
def test_start_and_stop_bzr_subprocess_with_error(self): |
|
374 |
"""finish_bzr_subprocess allows specification of the desired exit code. |
|
375 |
"""
|
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
376 |
process = self.start_bzr_subprocess(['--versionn']) |
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
377 |
result = self.finish_bzr_subprocess(process, retcode=3) |
378 |
self.assertEqual('', result[0]) |
|
379 |
self.assertContainsRe(result[1], 'unknown command') |
|
380 |
||
381 |
def test_start_and_stop_bzr_subprocess_ignoring_retcode(self): |
|
382 |
"""finish_bzr_subprocess allows the exit code to be ignored.""" |
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
383 |
process = self.start_bzr_subprocess(['--versionn']) |
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
384 |
result = self.finish_bzr_subprocess(process, retcode=None) |
385 |
self.assertEqual('', result[0]) |
|
386 |
self.assertContainsRe(result[1], 'unknown command') |
|
387 |
||
388 |
def test_start_and_stop_bzr_subprocess_with_unexpected_retcode(self): |
|
389 |
"""finish_bzr_subprocess raises self.failureException if the retcode is |
|
390 |
not the expected one.
|
|
391 |
"""
|
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
392 |
process = self.start_bzr_subprocess(['--versionn']) |
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
393 |
self.assertRaises(self.failureException, self.finish_bzr_subprocess, |
394 |
process, retcode=0) |
|
395 |
||
396 |
def test_start_and_stop_bzr_subprocess_send_signal(self): |
|
397 |
"""finish_bzr_subprocess raises self.failureException if the retcode is |
|
398 |
not the expected one.
|
|
399 |
"""
|
|
|
1910.17.9
by Andrew Bennetts
Add skip_if_plan_to_signal flag to start_bzr_subprocess. |
400 |
process = self.start_bzr_subprocess(['wait-until-signalled'], |
401 |
skip_if_plan_to_signal=True) |
|
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
402 |
self.assertEqual('running\n', process.stdout.readline()) |
403 |
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT, |
|
404 |
retcode=3) |
|
405 |
self.assertEqual('', result[0]) |
|
406 |
self.assertEqual('bzr: interrupted\n', result[1]) |
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
407 |
|
408 |
def test_start_and_stop_working_dir(self): |
|
409 |
cwd = osutils.getcwd() |
|
410 |
||
411 |
self.make_branch_and_tree('one') |
|
412 |
||
413 |
process = self.start_bzr_subprocess(['root'], working_dir='one') |
|
414 |
result = self.finish_bzr_subprocess(process) |
|
415 |
self.assertEndsWith(result[0], 'one\n') |
|
416 |
self.assertEqual('', result[1]) |
|
|
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
417 |
|
|
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
418 |
|
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
419 |
class TestRunBzrError(ExternalBase): |
420 |
||
421 |
def test_run_bzr_error(self): |
|
422 |
out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0) |
|
423 |
self.assertEqual(out, 'it sure does!\n') |
|
424 |
||
425 |
out, err = self.run_bzr_error(["'foobarbaz' is not a versioned file"], |
|
426 |
'file-id', 'foobarbaz') |