2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
1 |
# Copyright (C) 2005, 2007 Canonical Ltd
|
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. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
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.
|
|
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. |
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""UI tests for the test framework."""
|
|
18 |
||
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
19 |
import os |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
20 |
import re |
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
21 |
import signal |
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
22 |
import sys |
23 |
||
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. |
24 |
import bzrlib |
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
25 |
from bzrlib import ( |
26 |
osutils, |
|
27 |
)
|
|
2394.2.3
by Ian Clatworthy
Backed out test junk |
28 |
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. |
29 |
from bzrlib.tests import ( |
30 |
TestCase, |
|
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
31 |
TestCaseInTempDir, |
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
32 |
TestCaseWithMemoryTransport, |
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
33 |
TestCaseWithTransport, |
2294.4.4
by Vincent Ladeuil
Provide a better implementation for testing passwords. |
34 |
TestUIFactory, |
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. |
35 |
TestSkipped, |
36 |
)
|
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
37 |
from bzrlib.symbol_versioning import ( |
38 |
zero_eighteen, |
|
39 |
)
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
40 |
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. |
41 |
|
42 |
||
43 |
class TestOptions(TestCase): |
|
44 |
||
45 |
current_test = None |
|
46 |
||
47 |
def test_transport_set_to_sftp(self): |
|
48 |
# test the --transport option has taken effect from within the
|
|
49 |
# test_transport test
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
50 |
try: |
51 |
import bzrlib.transport.sftp |
|
52 |
except ParamikoNotPresent: |
|
53 |
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. |
54 |
if TestOptions.current_test != "test_transport_set_to_sftp": |
55 |
return
|
|
56 |
self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer, |
|
57 |
bzrlib.tests.default_transport) |
|
58 |
||
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
59 |
def test_transport_set_to_memory(self): |
60 |
# test the --transport option has taken effect from within the
|
|
61 |
# test_transport test
|
|
62 |
import bzrlib.transport.memory |
|
63 |
if TestOptions.current_test != "test_transport_set_to_memory": |
|
64 |
return
|
|
65 |
self.assertEqual(bzrlib.transport.memory.MemoryServer, |
|
66 |
bzrlib.tests.default_transport) |
|
67 |
||
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. |
68 |
def test_transport(self): |
69 |
# test that --transport=sftp works
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
70 |
try: |
71 |
import bzrlib.transport.sftp |
|
72 |
except ParamikoNotPresent: |
|
73 |
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. |
74 |
old_transport = bzrlib.tests.default_transport |
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
75 |
old_root = TestCaseWithMemoryTransport.TEST_ROOT |
76 |
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. |
77 |
try: |
78 |
TestOptions.current_test = "test_transport_set_to_sftp" |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
79 |
stdout = self.run_bzr( |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
80 |
'selftest --transport=sftp test_transport_set_to_sftp')[0] |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
81 |
self.assertContainsRe(stdout, 'Ran 1 test') |
82 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
83 |
||
84 |
TestOptions.current_test = "test_transport_set_to_memory" |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
85 |
stdout = self.run_bzr( |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
86 |
'selftest --transport=memory test_transport_set_to_memory')[0] |
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. |
87 |
self.assertContainsRe(stdout, 'Ran 1 test') |
88 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
89 |
finally: |
|
90 |
bzrlib.tests.default_transport = old_transport |
|
91 |
TestOptions.current_test = None |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
92 |
TestCaseWithMemoryTransport.TEST_ROOT = old_root |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
93 |
|
94 |
||
95 |
class TestRunBzr(ExternalBase): |
|
96 |
||
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
97 |
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None, |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
98 |
working_dir=None): |
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
99 |
"""Override _run_bzr_core to test how it is invoked by run_bzr.
|
2027.5.3
by John Arbash Meinel
Add docstring to why run_bzr_captured is overridden |
100 |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
101 |
Attempts to run bzr from inside this class don't actually run it.
|
102 |
||
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
103 |
We test how run_bzr actually invokes bzr in another location.
|
2027.5.3
by John Arbash Meinel
Add docstring to why run_bzr_captured is overridden |
104 |
Here we only need to test that it is run_bzr passes the right
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
105 |
parameters to run_bzr.
|
2027.5.3
by John Arbash Meinel
Add docstring to why run_bzr_captured is overridden |
106 |
"""
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
107 |
self.argv = list(argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
108 |
self.retcode = retcode |
109 |
self.encoding = encoding |
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
110 |
self.stdin = stdin |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
111 |
self.working_dir = working_dir |
2292.1.28
by Marius Kruger
* NEWS |
112 |
return '', '' |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
113 |
|
114 |
def test_args(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
115 |
"""Test that run_bzr passes args correctly to _run_bzr_core"""
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
116 |
## self.callDeprecated(
|
117 |
## ['passing varargs to run_bzr was deprecated in version 0.18.'],
|
|
118 |
## self.run_bzr,
|
|
119 |
## 'arg1', 'arg2', 'arg3', retcode=1)
|
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
120 |
self.run_bzr('arg1', 'arg2', 'arg3', retcode=1) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
121 |
self.assertEqual(['arg1', 'arg2', 'arg3'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
122 |
|
123 |
def test_encoding(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
124 |
"""Test that run_bzr passes encoding to _run_bzr_core"""
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
125 |
self.run_bzr('foo bar') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
126 |
self.assertEqual(None, self.encoding) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
127 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
128 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
129 |
self.run_bzr('foo bar', encoding='baz') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
130 |
self.assertEqual('baz', self.encoding) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
131 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
132 |
|
133 |
def test_retcode(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
134 |
"""Test that run_bzr passes retcode to _run_bzr_core"""
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
135 |
# Default is retcode == 0
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
136 |
self.run_bzr('foo bar') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
137 |
self.assertEqual(0, self.retcode) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
138 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
139 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
140 |
self.run_bzr('foo bar', retcode=1) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
141 |
self.assertEqual(1, self.retcode) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
142 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
143 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
144 |
self.run_bzr('foo bar', retcode=None) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
145 |
self.assertEqual(None, self.retcode) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
146 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
147 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
148 |
self.run_bzr(['foo', 'bar'], retcode=3) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
149 |
self.assertEqual(3, self.retcode) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
150 |
self.assertEqual(['foo', 'bar'], self.argv) |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
151 |
|
152 |
def test_stdin(self): |
|
153 |
# test that the stdin keyword to run_bzr is passed through to
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
154 |
# _run_bzr_core as-is. We do this by overriding
|
155 |
# _run_bzr_core in this class, and then calling run_bzr,
|
|
156 |
# which is a convenience function for _run_bzr_core, so
|
|
1687.1.15
by Robert Collins
Review comments. |
157 |
# should invoke it.
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
158 |
self.run_bzr('foo bar', stdin='gam') |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
159 |
self.assertEqual('gam', self.stdin) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
160 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
161 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
162 |
self.run_bzr('foo bar', stdin='zippy') |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
163 |
self.assertEqual('zippy', self.stdin) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
164 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
165 |
|
166 |
def test_working_dir(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
167 |
"""Test that run_bzr passes working_dir to _run_bzr_core"""
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
168 |
self.run_bzr('foo bar') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
169 |
self.assertEqual(None, self.working_dir) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
170 |
self.assertEqual(['foo', 'bar'], self.argv) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
171 |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
172 |
self.run_bzr('foo bar', working_dir='baz') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
173 |
self.assertEqual('baz', self.working_dir) |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
174 |
self.assertEqual(['foo', 'bar'], self.argv) |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
175 |
|
176 |
||
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
177 |
class TestBenchmarkTests(TestCaseWithTransport): |
178 |
||
179 |
def test_benchmark_runs_benchmark_tests(self): |
|
180 |
"""bzr selftest --benchmark should not run the default test suite."""
|
|
181 |
# We test this by passing a regression test name to --benchmark, which
|
|
182 |
# should result in 0 rests run.
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
183 |
old_root = TestCaseWithMemoryTransport.TEST_ROOT |
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
184 |
try: |
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
185 |
TestCaseWithMemoryTransport.TEST_ROOT = None |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
186 |
out, err = self.run_bzr(['selftest', '--benchmark', |
187 |
'workingtree_implementations']) |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
188 |
finally: |
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
189 |
TestCaseWithMemoryTransport.TEST_ROOT = old_root |
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
190 |
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK') |
191 |
self.assertEqual( |
|
2095.4.1
by Martin Pool
Better progress bars during tests |
192 |
'tests passed\n', |
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
193 |
err) |
194 |
benchfile = open(".perf_history", "rt") |
|
195 |
try: |
|
196 |
lines = benchfile.readlines() |
|
197 |
finally: |
|
198 |
benchfile.close() |
|
199 |
self.assertEqual(1, len(lines)) |
|
200 |
self.assertContainsRe(lines[0], "--date [0-9.]+") |
|
201 |
||
202 |
||
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
203 |
class TestRunBzrCaptured(ExternalBase): |
204 |
||
205 |
def apply_redirected(self, stdin=None, stdout=None, stderr=None, |
|
206 |
a_callable=None, *args, **kwargs): |
|
207 |
self.stdin = stdin |
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
208 |
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. |
209 |
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 |
210 |
self.working_dir = osutils.getcwd() |
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
211 |
stdout.write('foo\n') |
212 |
stderr.write('bar\n') |
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
213 |
return 0 |
214 |
||
215 |
def test_stdin(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
216 |
# test that the stdin keyword to _run_bzr_core is passed through to
|
1687.1.15
by Robert Collins
Review comments. |
217 |
# apply_redirected as a StringIO. We do this by overriding
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
218 |
# apply_redirected in this class, and then calling _run_bzr_core,
|
1687.1.15
by Robert Collins
Review comments. |
219 |
# which calls apply_redirected.
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
220 |
self.run_bzr(['foo', 'bar'], stdin='gam') |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
221 |
self.assertEqual('gam', self.stdin.read()) |
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
222 |
self.assertTrue(self.stdin is self.factory_stdin) |
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
223 |
self.run_bzr(['foo', 'bar'], stdin='zippy') |
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
224 |
self.assertEqual('zippy', self.stdin.read()) |
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
225 |
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. |
226 |
|
227 |
def test_ui_factory(self): |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
228 |
# each invocation of self.run_bzr should get its
|
2294.4.4
by Vincent Ladeuil
Provide a better implementation for testing passwords. |
229 |
# own UI factory, which is an instance of TestUIFactory,
|
230 |
# with stdin, stdout and stderr attached to the stdin,
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
231 |
# stdout and stderr of the invoked run_bzr
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
232 |
current_factory = bzrlib.ui.ui_factory |
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
233 |
self.run_bzr(['foo']) |
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
234 |
self.failIf(current_factory is self.factory) |
235 |
self.assertNotEqual(sys.stdout, self.factory.stdout) |
|
236 |
self.assertNotEqual(sys.stderr, self.factory.stderr) |
|
237 |
self.assertEqual('foo\n', self.factory.stdout.getvalue()) |
|
238 |
self.assertEqual('bar\n', self.factory.stderr.getvalue()) |
|
2294.4.4
by Vincent Ladeuil
Provide a better implementation for testing passwords. |
239 |
self.assertIsInstance(self.factory, TestUIFactory) |
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
240 |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
241 |
def test_working_dir(self): |
242 |
self.build_tree(['one/', 'two/']) |
|
243 |
cwd = osutils.getcwd() |
|
244 |
||
245 |
# Default is to work in the current directory
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
246 |
self.run_bzr(['foo', 'bar']) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
247 |
self.assertEqual(cwd, self.working_dir) |
248 |
||
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
249 |
self.run_bzr(['foo', 'bar'], working_dir=None) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
250 |
self.assertEqual(cwd, self.working_dir) |
251 |
||
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
252 |
# The function should be run in the alternative directory
|
253 |
# but afterwards the current working dir shouldn't be changed
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
254 |
self.run_bzr(['foo', 'bar'], working_dir='one') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
255 |
self.assertNotEqual(cwd, self.working_dir) |
256 |
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 |
257 |
self.assertEqual(cwd, osutils.getcwd()) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
258 |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
259 |
self.run_bzr(['foo', 'bar'], working_dir='two') |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
260 |
self.assertNotEqual(cwd, self.working_dir) |
261 |
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 |
262 |
self.assertEqual(cwd, osutils.getcwd()) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
263 |
|
264 |
||
265 |
class TestRunBzrSubprocess(TestCaseWithTransport): |
|
266 |
||
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
267 |
def test_run_bzr_subprocess(self): |
268 |
"""The run_bzr_helper_external comand behaves nicely."""
|
|
269 |
result = self.run_bzr_subprocess('--version') |
|
270 |
result = self.run_bzr_subprocess('--version', retcode=None) |
|
271 |
self.assertContainsRe(result[0], 'is free software') |
|
272 |
self.assertRaises(AssertionError, self.run_bzr_subprocess, |
|
273 |
'--versionn') |
|
274 |
result = self.run_bzr_subprocess('--versionn', retcode=3) |
|
275 |
result = self.run_bzr_subprocess('--versionn', retcode=None) |
|
276 |
self.assertContainsRe(result[1], 'unknown command') |
|
1857.1.20
by Aaron Bentley
Strip out all the EnumOption stuff |
277 |
err = self.run_bzr_subprocess('merge', '--merge-type', 'magic merge', |
278 |
retcode=3)[1] |
|
2221.4.15
by Aaron Bentley
Use RegistryOption for merge type |
279 |
self.assertContainsRe(err, 'Bad value "magic merge" for option' |
280 |
' "merge-type"') |
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
281 |
|
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
282 |
def test_run_bzr_subprocess_env(self): |
283 |
"""run_bzr_subprocess can set environment variables in the child only.
|
|
284 |
||
285 |
These changes should not change the running process, only the child.
|
|
286 |
"""
|
|
287 |
# The test suite should unset this variable
|
|
288 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
289 |
out, err = self.run_bzr_subprocess('whoami', env_changes={ |
|
290 |
'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 |
291 |
}, universal_newlines=True) |
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
292 |
self.assertEqual('', err) |
293 |
self.assertEqual('Joe Foo <joe@foo.com>\n', out) |
|
294 |
# And it should not be modified
|
|
295 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
296 |
||
297 |
# Do it again with a different address, just to make sure
|
|
298 |
# it is actually changing
|
|
299 |
out, err = self.run_bzr_subprocess('whoami', env_changes={ |
|
300 |
'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 |
301 |
}, universal_newlines=True) |
1963.1.1
by John Arbash Meinel
run_bzr_subprocess() can take an env_changes parameter |
302 |
self.assertEqual('', err) |
303 |
self.assertEqual('Barry <bar@foo.com>\n', out) |
|
304 |
self.assertEqual(None, os.environ.get('BZR_EMAIL')) |
|
305 |
||
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
306 |
def test_run_bzr_subprocess_env_del(self): |
307 |
"""run_bzr_subprocess can remove environment variables too."""
|
|
308 |
# Create a random email, so we are sure this won't collide
|
|
309 |
rand_bzr_email = 'John Doe <jdoe@%s.com>' % (osutils.rand_chars(20),) |
|
310 |
rand_email = 'Jane Doe <jdoe@%s.com>' % (osutils.rand_chars(20),) |
|
311 |
os.environ['BZR_EMAIL'] = rand_bzr_email |
|
312 |
os.environ['EMAIL'] = rand_email |
|
313 |
try: |
|
314 |
# 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 |
315 |
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 |
316 |
self.assertEqual('', err) |
317 |
self.assertEqual(rand_bzr_email + '\n', out) |
|
318 |
||
319 |
# Now that BZR_EMAIL is not set, it should fall back to EMAIL
|
|
320 |
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 |
321 |
env_changes={'BZR_EMAIL':None}, |
322 |
universal_newlines=True) |
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
323 |
self.assertEqual('', err) |
324 |
self.assertEqual(rand_email + '\n', out) |
|
325 |
||
326 |
# This switches back to the default email guessing logic
|
|
327 |
# Which shouldn't match either of the above addresses
|
|
328 |
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 |
329 |
env_changes={'BZR_EMAIL':None, 'EMAIL':None}, |
330 |
universal_newlines=True) |
|
1963.1.2
by John Arbash Meinel
Cleanups suggested by Martin, add test that env_changes can remove an env variable |
331 |
|
332 |
self.assertEqual('', err) |
|
333 |
self.assertNotEqual(rand_bzr_email + '\n', out) |
|
334 |
self.assertNotEqual(rand_email + '\n', out) |
|
335 |
finally: |
|
336 |
# TestCase cleans up BZR_EMAIL, and EMAIL at startup
|
|
337 |
del os.environ['BZR_EMAIL'] |
|
338 |
del os.environ['EMAIL'] |
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
339 |
|
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
340 |
def test_run_bzr_subprocess_env_del_missing(self): |
341 |
"""run_bzr_subprocess won't fail if deleting a nonexistant env var"""
|
|
342 |
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ) |
|
343 |
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 |
344 |
env_changes={'NON_EXISTANT_ENV_VAR':None}, |
345 |
universal_newlines=True) |
|
2227.4.1
by v.ladeuil+lp at free
Fix #78026. |
346 |
self.assertEqual('It sure does!\n', out) |
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 |
347 |
self.assertEqual('', err) |
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
348 |
|
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
349 |
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 |
350 |
"""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 |
351 |
cwd = osutils.getcwd() |
352 |
||
353 |
self.make_branch_and_tree('.') |
|
354 |
self.make_branch_and_tree('one') |
|
355 |
self.make_branch_and_tree('two') |
|
356 |
||
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
357 |
def get_root(**kwargs): |
358 |
"""Spawn a process to get the 'root' of the tree.
|
|
359 |
||
360 |
You can pass in arbitrary new arguments. This just makes
|
|
361 |
sure that the returned path doesn't have trailing whitespace.
|
|
362 |
"""
|
|
363 |
return self.run_bzr_subprocess('root', **kwargs)[0].rstrip() |
|
364 |
||
365 |
self.assertEqual(cwd, get_root()) |
|
366 |
self.assertEqual(cwd, get_root(working_dir=None)) |
|
367 |
# Has our path changed?
|
|
368 |
self.assertEqual(cwd, osutils.getcwd()) |
|
369 |
||
370 |
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 |
371 |
self.assertEndsWith(dir1, 'one') |
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
372 |
self.assertEqual(cwd, osutils.getcwd()) |
373 |
||
374 |
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 |
375 |
self.assertEndsWith(dir2, 'two') |
2027.5.2
by John Arbash Meinel
add tests that the working directory is preserved, cleanup run_bzr_subprocess |
376 |
self.assertEqual(cwd, osutils.getcwd()) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
377 |
|
378 |
||
2067.2.2
by John Arbash Meinel
Review comments from Robert |
379 |
class _DontSpawnProcess(Exception): |
380 |
"""A simple exception which just allows us to skip unnecessary steps"""
|
|
381 |
||
382 |
||
383 |
class TestRunBzrSubprocessCommands(TestCaseWithTransport): |
|
384 |
||
385 |
def _popen(self, *args, **kwargs): |
|
386 |
"""Record the command that is run, so that we can ensure it is correct"""
|
|
387 |
self._popen_args = args |
|
388 |
self._popen_kwargs = kwargs |
|
389 |
raise _DontSpawnProcess() |
|
390 |
||
391 |
def test_run_bzr_subprocess_no_plugins(self): |
|
392 |
self.assertRaises(_DontSpawnProcess, self.run_bzr_subprocess) |
|
393 |
command = self._popen_args[0] |
|
394 |
self.assertEqual(sys.executable, command[0]) |
|
395 |
self.assertEqual(self.get_bzr_path(), command[1]) |
|
396 |
self.assertEqual(['--no-plugins'], command[2:]) |
|
397 |
||
398 |
def test_allow_plugins(self): |
|
2067.2.4
by John Arbash Meinel
fixup one test |
399 |
self.assertRaises(_DontSpawnProcess, |
400 |
self.run_bzr_subprocess, allow_plugins=True) |
|
2067.2.2
by John Arbash Meinel
Review comments from Robert |
401 |
command = self._popen_args[0] |
402 |
self.assertEqual([], command[2:]) |
|
403 |
||
404 |
||
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
405 |
class TestBzrSubprocess(TestCaseWithTransport): |
406 |
||
1910.17.2
by Andrew Bennetts
Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue |
407 |
def test_start_and_stop_bzr_subprocess(self): |
408 |
"""We can start and perform other test actions while that process is
|
|
409 |
still alive.
|
|
410 |
"""
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
411 |
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 |
412 |
result = self.finish_bzr_subprocess(process) |
413 |
self.assertContainsRe(result[0], 'is free software') |
|
414 |
self.assertEqual('', result[1]) |
|
415 |
||
416 |
def test_start_and_stop_bzr_subprocess_with_error(self): |
|
417 |
"""finish_bzr_subprocess allows specification of the desired exit code.
|
|
418 |
"""
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
419 |
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 |
420 |
result = self.finish_bzr_subprocess(process, retcode=3) |
421 |
self.assertEqual('', result[0]) |
|
422 |
self.assertContainsRe(result[1], 'unknown command') |
|
423 |
||
424 |
def test_start_and_stop_bzr_subprocess_ignoring_retcode(self): |
|
425 |
"""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. |
426 |
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 |
427 |
result = self.finish_bzr_subprocess(process, retcode=None) |
428 |
self.assertEqual('', result[0]) |
|
429 |
self.assertContainsRe(result[1], 'unknown command') |
|
430 |
||
431 |
def test_start_and_stop_bzr_subprocess_with_unexpected_retcode(self): |
|
432 |
"""finish_bzr_subprocess raises self.failureException if the retcode is
|
|
433 |
not the expected one.
|
|
434 |
"""
|
|
1910.17.8
by Andrew Bennetts
Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess. |
435 |
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 |
436 |
self.assertRaises(self.failureException, self.finish_bzr_subprocess, |
437 |
process, retcode=0) |
|
438 |
||
439 |
def test_start_and_stop_bzr_subprocess_send_signal(self): |
|
440 |
"""finish_bzr_subprocess raises self.failureException if the retcode is
|
|
441 |
not the expected one.
|
|
442 |
"""
|
|
1910.17.9
by Andrew Bennetts
Add skip_if_plan_to_signal flag to start_bzr_subprocess. |
443 |
process = self.start_bzr_subprocess(['wait-until-signalled'], |
444 |
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 |
445 |
self.assertEqual('running\n', process.stdout.readline()) |
446 |
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT, |
|
447 |
retcode=3) |
|
448 |
self.assertEqual('', result[0]) |
|
449 |
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 |
450 |
|
451 |
def test_start_and_stop_working_dir(self): |
|
452 |
cwd = osutils.getcwd() |
|
453 |
||
454 |
self.make_branch_and_tree('one') |
|
455 |
||
456 |
process = self.start_bzr_subprocess(['root'], working_dir='one') |
|
2156.1.1
by v.ladeuil+lp at free
Make the test compatible with windows. |
457 |
result = self.finish_bzr_subprocess(process, universal_newlines=True) |
2027.5.1
by John Arbash Meinel
Add working_dir=XX to run_bzr_* functions, and clean up tests |
458 |
self.assertEndsWith(result[0], 'one\n') |
459 |
self.assertEqual('', result[1]) |
|
2156.1.1
by v.ladeuil+lp at free
Make the test compatible with windows. |
460 |
|
1963.1.4
by John Arbash Meinel
env_changes={} should be safe to remove variables that aren't there |
461 |
|
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
462 |
class TestRunBzrError(ExternalBase): |
463 |
||
464 |
def test_run_bzr_error(self): |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
465 |
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=0) |
2227.4.1
by v.ladeuil+lp at free
Fix #78026. |
466 |
self.assertEqual(out, 'It sure does!\n') |
1871.1.1
by Robert Collins
Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py. |
467 |
|
2067.3.1
by Martin Pool
Clean up BzrNewError, other exception classes and users. |
468 |
out, err = self.run_bzr_error(["bzr: ERROR: foobarbaz is not versioned"], |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
469 |
['file-id', 'foobarbaz']) |
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
470 |
|
471 |
||
472 |
class TestSelftestCleanOutput(TestCaseInTempDir): |
|
473 |
||
474 |
def test_clean_output(self): |
|
475 |
# check that 'bzr selftest --clean-output' works correct
|
|
476 |
dirs = ('test0000.tmp', 'test0001.tmp', 'bzrlib', 'tests') |
|
477 |
files = ('bzr', 'setup.py', 'test9999.tmp') |
|
478 |
for i in dirs: |
|
479 |
os.mkdir(i) |
|
480 |
for i in files: |
|
481 |
f = file(i, 'wb') |
|
482 |
f.write('content of ') |
|
483 |
f.write(i) |
|
484 |
f.close() |
|
485 |
||
486 |
root = os.getcwdu() |
|
487 |
before = os.listdir(root) |
|
2172.4.5
by Alexander Belchenko
Small fix: output of os.listdir() should be sorted manually |
488 |
before.sort() |
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
489 |
self.assertEquals(['bzr','bzrlib','setup.py', |
490 |
'test0000.tmp','test0001.tmp', |
|
491 |
'test9999.tmp','tests'], |
|
492 |
before) |
|
493 |
||
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
494 |
out, err = self.run_bzr(['selftest','--clean-output'], |
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
495 |
working_dir=root) |
496 |
||
2193.1.1
by Martin Pool
test_clean_output: don't depend on directories being cleaned up in order. |
497 |
self.assertEquals(['delete directory: test0000.tmp', |
498 |
'delete directory: test0001.tmp'], |
|
499 |
sorted(out.splitlines())) |
|
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
500 |
self.assertEquals('', err) |
501 |
||
502 |
after = os.listdir(root) |
|
2172.4.5
by Alexander Belchenko
Small fix: output of os.listdir() should be sorted manually |
503 |
after.sort() |
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
504 |
self.assertEquals(['bzr','bzrlib','setup.py', |
505 |
'test9999.tmp','tests'], |
|
506 |
after) |
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
507 |
|
508 |
||
2394.2.6
by Ian Clatworthy
completed blackbox tests |
509 |
class TestSelftestListOnly(TestCase): |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
510 |
|
511 |
@staticmethod
|
|
2394.2.6
by Ian Clatworthy
completed blackbox tests |
512 |
def _parse_test_list(lines, newlines_in_header=1): |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
513 |
"Parse a list of lines into a tuple of 3 lists (header,body,footer)."
|
514 |
||
515 |
in_header = True |
|
516 |
in_footer = False |
|
517 |
header = [] |
|
518 |
body = [] |
|
2394.2.6
by Ian Clatworthy
completed blackbox tests |
519 |
footer = [] |
520 |
header_newlines_found = 0 |
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
521 |
for line in lines: |
522 |
if in_header: |
|
523 |
if line == '': |
|
2394.2.6
by Ian Clatworthy
completed blackbox tests |
524 |
header_newlines_found += 1 |
525 |
if header_newlines_found >= newlines_in_header: |
|
526 |
in_header = False |
|
527 |
continue
|
|
528 |
header.append(line) |
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
529 |
elif not in_footer: |
530 |
if line.startswith('-------'): |
|
531 |
in_footer = True |
|
532 |
else: |
|
533 |
body.append(line) |
|
534 |
else: |
|
535 |
footer.append(line) |
|
536 |
# If the last body line is blank, drop it off the list
|
|
537 |
if len(body) > 0 and body[-1] == '': |
|
538 |
body.pop() |
|
539 |
return (header,body,footer) |
|
540 |
||
541 |
def test_list_only(self): |
|
542 |
# check that bzr selftest --list-only works correctly
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
543 |
out,err = self.run_bzr(['selftest', 'selftest', |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
544 |
'--list-only']) |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
545 |
self.assertEndsWith(err, 'tests passed\n') |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
546 |
(header,body,footer) = self._parse_test_list(out.splitlines()) |
2394.2.8
by Ian Clatworthy
incorporate feedback from jam |
547 |
num_tests = len(body) |
548 |
self.assertContainsRe(footer[0], 'Listed %s tests in' % num_tests) |
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
549 |
|
2394.2.6
by Ian Clatworthy
completed blackbox tests |
550 |
def test_list_only_filtered(self): |
551 |
# check that a filtered --list-only works, both include and exclude
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
552 |
out_all,err_all = self.run_bzr(['selftest', '--list-only']) |
2394.2.5
by Ian Clatworthy
list-only working, include test not |
553 |
tests_all = self._parse_test_list(out_all.splitlines())[1] |
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
554 |
out_incl,err_incl = self.run_bzr(['selftest', '--list-only', |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
555 |
'selftest']) |
556 |
tests_incl = self._parse_test_list(out_incl.splitlines())[1] |
|
557 |
self.assertSubset(tests_incl, tests_all) |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
558 |
out_excl,err_excl = self.run_bzr(['selftest', '--list-only', |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
559 |
'--exclude', 'selftest']) |
560 |
tests_excl = self._parse_test_list(out_excl.splitlines())[1] |
|
561 |
self.assertSubset(tests_excl, tests_all) |
|
562 |
set_incl = set(tests_incl) |
|
563 |
set_excl = set(tests_excl) |
|
564 |
intersection = set_incl.intersection(set_excl) |
|
565 |
self.assertEquals(0, len(intersection)) |
|
566 |
self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl)) |
|
567 |
||
568 |
def test_list_only_random(self): |
|
569 |
# check that --randomize works correctly
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
570 |
out_all,err_all = self.run_bzr(['selftest', '--list-only', |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
571 |
'selftest']) |
572 |
tests_all = self._parse_test_list(out_all.splitlines())[1] |
|
2477.1.6
by Martin Pool
doc |
573 |
# XXX: It looks like there are some orders for generating tests that
|
574 |
# fail as of 20070504 - maybe because of import order dependencies.
|
|
575 |
# So unfortunately this will rarely intermittently fail at the moment.
|
|
576 |
# -- mbp 20070504
|
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
577 |
out_rand,err_rand = self.run_bzr(['selftest', '--list-only', |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
578 |
'selftest', '--randomize', 'now']) |
579 |
(header_rand,tests_rand,dummy) = self._parse_test_list( |
|
580 |
out_rand.splitlines(), 2) |
|
581 |
self.assertNotEqual(tests_all, tests_rand) |
|
582 |
self.assertEqual(sorted(tests_all), sorted(tests_rand)) |
|
583 |
# Check that the seed can be reused to get the exact same order
|
|
584 |
seed_re = re.compile('Randomizing test order using seed (\w+)') |
|
585 |
match_obj = seed_re.search(header_rand[-1]) |
|
586 |
seed = match_obj.group(1) |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
587 |
out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only', |
2394.2.6
by Ian Clatworthy
completed blackbox tests |
588 |
'selftest', '--randomize', seed]) |
589 |
(header_rand2,tests_rand2,dummy) = self._parse_test_list( |
|
590 |
out_rand2.splitlines(), 2) |
|
591 |
self.assertEqual(tests_rand, tests_rand2) |
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
592 |