bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
608
by Martin Pool
- Split selftests out into a new module and start changing them |
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 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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
609
by Martin Pool
- cleanup test code |
17 |
|
|
1185.1.29
by Robert Collins
merge merge tweaks from aaron, which includes latest .dev |
18 |
from cStringIO import StringIO |
|
1185.16.16
by Martin Pool
- add TestCase.assertEqualDiffs helper |
19 |
import difflib |
20 |
import errno |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
21 |
import logging |
22 |
import os |
|
|
1185.16.16
by Martin Pool
- add TestCase.assertEqualDiffs helper |
23 |
import re |
24 |
import shutil |
|
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
25 |
import sys |
|
1185.16.16
by Martin Pool
- add TestCase.assertEqualDiffs helper |
26 |
import tempfile |
27 |
import unittest |
|
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
28 |
import time |
|
1185.52.1
by James Henstridge
Don't encode unicode messages to UTF-8 in mutter() (the stream writer does it). |
29 |
import codecs |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
30 |
|
|
1513
by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory. |
31 |
import bzrlib.branch |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
32 |
import bzrlib.commands |
|
1514
by Robert Collins
Unbreak self.build_tree_shape in tests. |
33 |
from bzrlib.errors import BzrError |
|
1513
by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory. |
34 |
import bzrlib.inventory |
35 |
import bzrlib.merge3 |
|
36 |
import bzrlib.osutils |
|
37 |
import bzrlib.osutils as osutils |
|
38 |
import bzrlib.plugin |
|
39 |
import bzrlib.store |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
40 |
import bzrlib.trace |
|
1185.43.1
by Martin Pool
Remove direct logging calls from selftest |
41 |
from bzrlib.trace import mutter |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
42 |
from bzrlib.tests.TestUtil import TestLoader, TestSuite |
|
1514
by Robert Collins
Unbreak self.build_tree_shape in tests. |
43 |
from bzrlib.tests.treeshape import build_tree_contents |
|
1147
by Martin Pool
- split builtin commands into separate module bzrlib.builtins; |
44 |
|
|
855
by Martin Pool
- Patch from John to allow plugins to add their own tests. |
45 |
MODULES_TO_TEST = [] |
|
1513
by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory. |
46 |
MODULES_TO_DOCTEST = [ |
47 |
bzrlib.branch, |
|
48 |
bzrlib.commands, |
|
49 |
bzrlib.errors, |
|
50 |
bzrlib.inventory, |
|
51 |
bzrlib.merge3, |
|
52 |
bzrlib.osutils, |
|
53 |
bzrlib.store, |
|
54 |
]
|
|
55 |
def packages_to_test(): |
|
56 |
import bzrlib.tests.blackbox |
|
57 |
return [ |
|
58 |
bzrlib.tests.blackbox |
|
59 |
]
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
60 |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
61 |
|
62 |
class EarlyStoppingTestResultAdapter(object): |
|
63 |
"""An adapter for TestResult to stop at the first first failure or error""" |
|
64 |
||
65 |
def __init__(self, result): |
|
66 |
self._result = result |
|
67 |
||
68 |
def addError(self, test, err): |
|
69 |
self._result.addError(test, err) |
|
70 |
self._result.stop() |
|
71 |
||
72 |
def addFailure(self, test, err): |
|
73 |
self._result.addFailure(test, err) |
|
74 |
self._result.stop() |
|
75 |
||
76 |
def __getattr__(self, name): |
|
77 |
return getattr(self._result, name) |
|
78 |
||
79 |
def __setattr__(self, name, value): |
|
80 |
if name == '_result': |
|
81 |
object.__setattr__(self, name, value) |
|
82 |
return setattr(self._result, name, value) |
|
83 |
||
84 |
||
85 |
class _MyResult(unittest._TextTestResult): |
|
|
1185.43.2
by Martin Pool
Nicer display of verbose test results and progress |
86 |
"""Custom TestResult. |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
87 |
|
|
1185.33.54
by Martin Pool
[merge] test renames and other fixes (John) |
88 |
Shows output in a different format, including displaying runtime for tests.
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
89 |
"""
|
90 |
||
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
91 |
def _elapsedTime(self): |
|
1185.43.2
by Martin Pool
Nicer display of verbose test results and progress |
92 |
return "%5dms" % (1000 * (time.time() - self._start_time)) |
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
93 |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
94 |
def startTest(self, test): |
95 |
unittest.TestResult.startTest(self, test) |
|
|
1185.31.17
by John Arbash Meinel
Shorten test names in verbose mode in a logical way. Removed bzrlib.selftest prefix |
96 |
# In a short description, the important words are in
|
97 |
# the beginning, but in an id, the important words are
|
|
98 |
# at the end
|
|
|
1185.33.54
by Martin Pool
[merge] test renames and other fixes (John) |
99 |
SHOW_DESCRIPTIONS = False |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
100 |
if self.showAll: |
|
1185.33.60
by Martin Pool
Use full terminal width for verbose test output. |
101 |
width = osutils.terminal_width() |
102 |
name_width = width - 15 |
|
103 |
what = None |
|
104 |
if SHOW_DESCRIPTIONS: |
|
105 |
what = test.shortDescription() |
|
106 |
if what: |
|
107 |
if len(what) > name_width: |
|
108 |
what = what[:name_width-3] + '...' |
|
109 |
if what is None: |
|
110 |
what = test.id() |
|
111 |
if what.startswith('bzrlib.tests.'): |
|
112 |
what = what[13:] |
|
113 |
if len(what) > name_width: |
|
114 |
what = '...' + what[3-name_width:] |
|
115 |
what = what.ljust(name_width) |
|
116 |
self.stream.write(what) |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
117 |
self.stream.flush() |
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
118 |
self._start_time = time.time() |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
119 |
|
120 |
def addError(self, test, err): |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
121 |
if isinstance(err[1], TestSkipped): |
122 |
return self.addSkipped(test, err) |
|
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
123 |
unittest.TestResult.addError(self, test, err) |
124 |
if self.showAll: |
|
125 |
self.stream.writeln("ERROR %s" % self._elapsedTime()) |
|
126 |
elif self.dots: |
|
127 |
self.stream.write('E') |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
128 |
self.stream.flush() |
129 |
||
130 |
def addFailure(self, test, err): |
|
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
131 |
unittest.TestResult.addFailure(self, test, err) |
132 |
if self.showAll: |
|
|
1185.43.2
by Martin Pool
Nicer display of verbose test results and progress |
133 |
self.stream.writeln(" FAIL %s" % self._elapsedTime()) |
|
1185.1.58
by Robert Collins
make selftest -v show the elapsed time for each test run. |
134 |
elif self.dots: |
135 |
self.stream.write('F') |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
136 |
self.stream.flush() |
137 |
||
138 |
def addSuccess(self, test): |
|
139 |
if self.showAll: |
|
|
1185.43.2
by Martin Pool
Nicer display of verbose test results and progress |
140 |
self.stream.writeln(' OK %s' % self._elapsedTime()) |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
141 |
elif self.dots: |
142 |
self.stream.write('~') |
|
143 |
self.stream.flush() |
|
144 |
unittest.TestResult.addSuccess(self, test) |
|
145 |
||
|
1185.33.96
by Martin Pool
Fix up display of reasons why tests were skipped. |
146 |
def addSkipped(self, test, skip_excinfo): |
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
147 |
if self.showAll: |
|
1185.33.96
by Martin Pool
Fix up display of reasons why tests were skipped. |
148 |
print >>self.stream, ' SKIP %s' % self._elapsedTime() |
149 |
print >>self.stream, ' %s' % skip_excinfo[1] |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
150 |
elif self.dots: |
151 |
self.stream.write('S') |
|
152 |
self.stream.flush() |
|
153 |
# seems best to treat this as success from point-of-view of unittest
|
|
154 |
# -- it actually does nothing so it barely matters :)
|
|
155 |
unittest.TestResult.addSuccess(self, test) |
|
156 |
||
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
157 |
def printErrorList(self, flavour, errors): |
158 |
for test, err in errors: |
|
159 |
self.stream.writeln(self.separator1) |
|
160 |
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test))) |
|
161 |
if hasattr(test, '_get_log'): |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
162 |
print >>self.stream |
163 |
print >>self.stream, \ |
|
164 |
('vvvv[log from %s]' % test).ljust(78,'-') |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
165 |
print >>self.stream, test._get_log() |
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
166 |
print >>self.stream, \ |
167 |
('^^^^[log from %s]' % test).ljust(78,'-') |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
168 |
self.stream.writeln(self.separator2) |
169 |
self.stream.writeln("%s" % err) |
|
170 |
||
171 |
||
172 |
class TextTestRunner(unittest.TextTestRunner): |
|
|
1185.16.58
by mbp at sourcefrog
- run all selftests by default |
173 |
stop_on_failure = False |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
174 |
|
175 |
def _makeResult(self): |
|
176 |
result = _MyResult(self.stream, self.descriptions, self.verbosity) |
|
|
1185.16.58
by mbp at sourcefrog
- run all selftests by default |
177 |
if self.stop_on_failure: |
178 |
result = EarlyStoppingTestResultAdapter(result) |
|
179 |
return result |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
180 |
|
181 |
||
|
1393.1.46
by Martin Pool
- bzr selftest arguments can be partial ids of tests to run |
182 |
def iter_suite_tests(suite): |
183 |
"""Return all tests in a suite, recursing through nested suites""" |
|
184 |
for item in suite._tests: |
|
185 |
if isinstance(item, unittest.TestCase): |
|
186 |
yield item |
|
187 |
elif isinstance(item, unittest.TestSuite): |
|
188 |
for r in iter_suite_tests(item): |
|
189 |
yield r |
|
190 |
else: |
|
191 |
raise Exception('unknown object %r inside test suite %r' |
|
192 |
% (item, suite)) |
|
193 |
||
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
194 |
|
195 |
class TestSkipped(Exception): |
|
196 |
"""Indicates that a test was intentionally skipped, rather than failing.""" |
|
197 |
# XXX: Not used yet
|
|
198 |
||
199 |
||
|
1147
by Martin Pool
- split builtin commands into separate module bzrlib.builtins; |
200 |
class CommandFailed(Exception): |
201 |
pass
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
202 |
|
203 |
class TestCase(unittest.TestCase): |
|
204 |
"""Base class for bzr unit tests. |
|
205 |
|
|
206 |
Tests that need access to disk resources should subclass
|
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
207 |
TestCaseInTempDir not TestCase.
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
208 |
|
209 |
Error and debug log messages are redirected from their usual
|
|
210 |
location into a temporary file, the contents of which can be
|
|
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
211 |
retrieved by _get_log(). We use a real OS file, not an in-memory object,
|
212 |
so that it can also capture file IO. When the test completes this file
|
|
213 |
is read into memory and removed from disk.
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
214 |
|
215 |
There are also convenience functions to invoke bzr's command-line
|
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
216 |
routine, and to build and check bzr trees.
|
217 |
|
|
218 |
In addition to the usual method of overriding tearDown(), this class also
|
|
219 |
allows subclasses to register functions into the _cleanups list, which is
|
|
220 |
run in order as the object is torn down. It's less likely this will be
|
|
221 |
accidentally overlooked.
|
|
222 |
"""
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
223 |
|
224 |
BZRPATH = 'bzr' |
|
|
1185.16.14
by Martin Pool
- make TestCase._get_log work even if setup was aborted |
225 |
_log_file_name = None |
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
226 |
_log_contents = '' |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
227 |
|
228 |
def setUp(self): |
|
229 |
unittest.TestCase.setUp(self) |
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
230 |
self._cleanups = [] |
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
231 |
self._cleanEnvironment() |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
232 |
bzrlib.trace.disable_default_logging() |
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
233 |
self._startLogFile() |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
234 |
|
|
1185.16.16
by Martin Pool
- add TestCase.assertEqualDiffs helper |
235 |
def _ndiff_strings(self, a, b): |
|
1185.16.67
by Martin Pool
- assertEqualDiff handles strings without trailing newline |
236 |
"""Return ndiff between two strings containing lines. |
237 |
|
|
238 |
A trailing newline is added if missing to make the strings
|
|
239 |
print properly."""
|
|
240 |
if b and b[-1] != '\n': |
|
241 |
b += '\n' |
|
242 |
if a and a[-1] != '\n': |
|
243 |
a += '\n' |
|
|
1185.16.21
by Martin Pool
- tweak diff shown by assertEqualDiff |
244 |
difflines = difflib.ndiff(a.splitlines(True), |
245 |
b.splitlines(True), |
|
246 |
linejunk=lambda x: False, |
|
247 |
charjunk=lambda x: False) |
|
248 |
return ''.join(difflines) |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
249 |
|
|
1185.16.16
by Martin Pool
- add TestCase.assertEqualDiffs helper |
250 |
def assertEqualDiff(self, a, b): |
251 |
"""Assert two texts are equal, if not raise an exception. |
|
252 |
|
|
253 |
This is intended for use with multi-line strings where it can
|
|
254 |
be hard to find the differences by eye.
|
|
255 |
"""
|
|
256 |
# TODO: perhaps override assertEquals to call this for strings?
|
|
257 |
if a == b: |
|
258 |
return
|
|
259 |
raise AssertionError("texts not equal:\n" + |
|
260 |
self._ndiff_strings(a, b)) |
|
|
1185.31.40
by John Arbash Meinel
Added osutils.mkdtemp() |
261 |
|
262 |
def assertStartsWith(self, s, prefix): |
|
263 |
if not s.startswith(prefix): |
|
264 |
raise AssertionError('string %r does not start with %r' % (s, prefix)) |
|
265 |
||
266 |
def assertEndsWith(self, s, suffix): |
|
267 |
if not s.endswith(prefix): |
|
268 |
raise AssertionError('string %r does not end with %r' % (s, suffix)) |
|
|
1185.16.42
by Martin Pool
- Add assertContainsRe |
269 |
|
270 |
def assertContainsRe(self, haystack, needle_re): |
|
271 |
"""Assert that a contains something matching a regular expression.""" |
|
272 |
if not re.search(needle_re, haystack): |
|
273 |
raise AssertionError('pattern "%s" not found in "%s"' |
|
274 |
% (needle_re, haystack)) |
|
|
1442.1.70
by Robert Collins
Add assertFileEqual to TestCaseInTempDir. |
275 |
|
|
1185.46.8
by Aaron Bentley
bzr add reports ignored patterns. |
276 |
def AssertSubset(self, sublist, superlist): |
277 |
"""Assert that every entry in sublist is present in superlist.""" |
|
278 |
missing = [] |
|
279 |
for entry in sublist: |
|
280 |
if entry not in superlist: |
|
281 |
missing.append(entry) |
|
282 |
if len(missing) > 0: |
|
283 |
raise AssertionError("value(s) %r not present in container %r" % |
|
284 |
(missing, superlist)) |
|
285 |
||
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
286 |
def _startLogFile(self): |
287 |
"""Send bzr and test log messages to a temporary file. |
|
288 |
||
289 |
The file is removed as the test is torn down.
|
|
290 |
"""
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
291 |
fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr') |
|
1185.52.1
by James Henstridge
Don't encode unicode messages to UTF-8 in mutter() (the stream writer does it). |
292 |
encoder, decoder, stream_reader, stream_writer = codecs.lookup('UTF-8') |
293 |
self._log_file = stream_writer(os.fdopen(fileno, 'w+')) |
|
|
1185.33.13
by Martin Pool
Hide more stuff in bzrlib.trace |
294 |
bzrlib.trace.enable_test_log(self._log_file) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
295 |
self._log_file_name = name |
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
296 |
self.addCleanup(self._finishLogFile) |
297 |
||
298 |
def _finishLogFile(self): |
|
299 |
"""Finished with the log file. |
|
300 |
||
301 |
Read contents into memory, close, and delete.
|
|
302 |
"""
|
|
|
1185.33.13
by Martin Pool
Hide more stuff in bzrlib.trace |
303 |
bzrlib.trace.disable_test_log() |
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
304 |
self._log_file.seek(0) |
305 |
self._log_contents = self._log_file.read() |
|
|
1185.16.122
by Martin Pool
[patch] Close test log file before deleting, needed on Windows |
306 |
self._log_file.close() |
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
307 |
os.remove(self._log_file_name) |
308 |
self._log_file = self._log_file_name = None |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
309 |
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
310 |
def addCleanup(self, callable): |
311 |
"""Arrange to run a callable when this case is torn down. |
|
312 |
||
313 |
Callables are run in the reverse of the order they are registered,
|
|
314 |
ie last-in first-out.
|
|
315 |
"""
|
|
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
316 |
if callable in self._cleanups: |
317 |
raise ValueError("cleanup function %r already registered on %s" |
|
318 |
% (callable, self)) |
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
319 |
self._cleanups.append(callable) |
320 |
||
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
321 |
def _cleanEnvironment(self): |
|
1185.38.3
by John Arbash Meinel
Refactored environment cleaning code |
322 |
new_env = { |
323 |
'HOME': os.getcwd(), |
|
324 |
'APPDATA': os.getcwd(), |
|
325 |
'BZREMAIL': None, |
|
326 |
'EMAIL': None, |
|
327 |
}
|
|
|
1185.38.4
by John Arbash Meinel
Making old_env a private member |
328 |
self.__old_env = {} |
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
329 |
self.addCleanup(self._restoreEnvironment) |
|
1185.38.3
by John Arbash Meinel
Refactored environment cleaning code |
330 |
for name, value in new_env.iteritems(): |
331 |
self._captureVar(name, value) |
|
332 |
||
333 |
||
334 |
def _captureVar(self, name, newvalue): |
|
335 |
"""Set an environment variable, preparing it to be reset when finished.""" |
|
|
1185.38.4
by John Arbash Meinel
Making old_env a private member |
336 |
self.__old_env[name] = os.environ.get(name, None) |
|
1185.38.3
by John Arbash Meinel
Refactored environment cleaning code |
337 |
if newvalue is None: |
338 |
if name in os.environ: |
|
339 |
del os.environ[name] |
|
340 |
else: |
|
341 |
os.environ[name] = newvalue |
|
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
342 |
|
|
1185.38.2
by John Arbash Meinel
[patch] Aaron Bentley's HOME fix. |
343 |
@staticmethod
|
344 |
def _restoreVar(name, value): |
|
345 |
if value is None: |
|
|
1185.38.3
by John Arbash Meinel
Refactored environment cleaning code |
346 |
if name in os.environ: |
347 |
del os.environ[name] |
|
|
1185.38.2
by John Arbash Meinel
[patch] Aaron Bentley's HOME fix. |
348 |
else: |
349 |
os.environ[name] = value |
|
350 |
||
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
351 |
def _restoreEnvironment(self): |
|
1185.38.4
by John Arbash Meinel
Making old_env a private member |
352 |
for name, value in self.__old_env.iteritems(): |
|
1185.38.3
by John Arbash Meinel
Refactored environment cleaning code |
353 |
self._restoreVar(name, value) |
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
354 |
|
355 |
def tearDown(self): |
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
356 |
self._runCleanups() |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
357 |
unittest.TestCase.tearDown(self) |
358 |
||
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
359 |
def _runCleanups(self): |
360 |
"""Run registered cleanup functions. |
|
361 |
||
362 |
This should only be called from TestCase.tearDown.
|
|
363 |
"""
|
|
|
1185.33.74
by Martin Pool
pychecker cleanups |
364 |
for cleanup_fn in reversed(self._cleanups): |
365 |
cleanup_fn() |
|
|
1185.16.108
by mbp at sourcefrog
Add TestCase.addCleanup method. |
366 |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
367 |
def log(self, *args): |
|
1185.43.1
by Martin Pool
Remove direct logging calls from selftest |
368 |
mutter(*args) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
369 |
|
370 |
def _get_log(self): |
|
371 |
"""Return as a string the log for this test""" |
|
|
1185.16.14
by Martin Pool
- make TestCase._get_log work even if setup was aborted |
372 |
if self._log_file_name: |
373 |
return open(self._log_file_name).read() |
|
374 |
else: |
|
|
1185.16.109
by mbp at sourcefrog
Clean up test log files when tests complete. |
375 |
return self._log_contents |
|
1185.43.1
by Martin Pool
Remove direct logging calls from selftest |
376 |
# TODO: Delete the log after it's been read in
|
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
377 |
|
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
378 |
def capture(self, cmd, retcode=0): |
|
1185.3.26
by Martin Pool
- remove remaining external executions of bzr |
379 |
"""Shortcut that splits cmd into words, runs, and returns stdout""" |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
380 |
return self.run_bzr_captured(cmd.split(), retcode=retcode)[0] |
|
1185.3.26
by Martin Pool
- remove remaining external executions of bzr |
381 |
|
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
382 |
def run_bzr_captured(self, argv, retcode=0): |
|
1185.22.7
by Michael Ellerman
Fix error in run_bzr_captured() doco |
383 |
"""Invoke bzr and return (stdout, stderr). |
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
384 |
|
385 |
Useful for code that wants to check the contents of the
|
|
386 |
output, the way error messages are presented, etc.
|
|
387 |
||
388 |
This should be the main method for tests that want to exercise the
|
|
389 |
overall behavior of the bzr application (rather than a unit test
|
|
390 |
or a functional test of the library.)
|
|
391 |
||
392 |
Much of the old code runs bzr by forking a new copy of Python, but
|
|
393 |
that is slower, harder to debug, and generally not necessary.
|
|
394 |
||
|
1185.3.20
by Martin Pool
- run_bzr_captured also includes logged errors in |
395 |
This runs bzr through the interface that catches and reports
|
396 |
errors, and with logging set to something approximating the
|
|
397 |
default, so that error reporting can be checked.
|
|
398 |
||
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
399 |
argv -- arguments to invoke bzr
|
400 |
retcode -- expected return code, or None for don't-care.
|
|
401 |
"""
|
|
402 |
stdout = StringIO() |
|
403 |
stderr = StringIO() |
|
404 |
self.log('run bzr: %s', ' '.join(argv)) |
|
|
1185.43.5
by Martin Pool
Update log message quoting |
405 |
# FIXME: don't call into logging here
|
|
1185.3.20
by Martin Pool
- run_bzr_captured also includes logged errors in |
406 |
handler = logging.StreamHandler(stderr) |
407 |
handler.setFormatter(bzrlib.trace.QuietFormatter()) |
|
408 |
handler.setLevel(logging.INFO) |
|
409 |
logger = logging.getLogger('') |
|
410 |
logger.addHandler(handler) |
|
411 |
try: |
|
412 |
result = self.apply_redirected(None, stdout, stderr, |
|
413 |
bzrlib.commands.run_bzr_catch_errors, |
|
414 |
argv) |
|
415 |
finally: |
|
416 |
logger.removeHandler(handler) |
|
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
417 |
out = stdout.getvalue() |
418 |
err = stderr.getvalue() |
|
419 |
if out: |
|
420 |
self.log('output:\n%s', out) |
|
421 |
if err: |
|
422 |
self.log('errors:\n%s', err) |
|
423 |
if retcode is not None: |
|
424 |
self.assertEquals(result, retcode) |
|
425 |
return out, err |
|
426 |
||
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
427 |
def run_bzr(self, *args, **kwargs): |
|
1119
by Martin Pool
doc |
428 |
"""Invoke bzr, as if it were run from the command line. |
429 |
||
430 |
This should be the main method for tests that want to exercise the
|
|
431 |
overall behavior of the bzr application (rather than a unit test
|
|
432 |
or a functional test of the library.)
|
|
433 |
||
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
434 |
This sends the stdout/stderr results into the test's log,
|
435 |
where it may be useful for debugging. See also run_captured.
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
436 |
"""
|
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
437 |
retcode = kwargs.pop('retcode', 0) |
|
1185.3.21
by Martin Pool
TestBase.run_bzr doesn't need to be deprecated |
438 |
return self.run_bzr_captured(args, retcode) |
|
1185.3.18
by Martin Pool
- add new helper TestBase.run_bzr_captured |
439 |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
440 |
def check_inventory_shape(self, inv, shape): |
|
1291
by Martin Pool
- add test for moving files between directories |
441 |
"""Compare an inventory to a list of expected names. |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
442 |
|
443 |
Fail if they are not precisely equal.
|
|
444 |
"""
|
|
445 |
extras = [] |
|
446 |
shape = list(shape) # copy |
|
447 |
for path, ie in inv.entries(): |
|
448 |
name = path.replace('\\', '/') |
|
449 |
if ie.kind == 'dir': |
|
450 |
name = name + '/' |
|
451 |
if name in shape: |
|
452 |
shape.remove(name) |
|
453 |
else: |
|
454 |
extras.append(name) |
|
455 |
if shape: |
|
456 |
self.fail("expected paths not found in inventory: %r" % shape) |
|
457 |
if extras: |
|
458 |
self.fail("unexpected paths found in inventory: %r" % extras) |
|
459 |
||
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
460 |
def apply_redirected(self, stdin=None, stdout=None, stderr=None, |
461 |
a_callable=None, *args, **kwargs): |
|
462 |
"""Call callable with redirected std io pipes. |
|
463 |
||
464 |
Returns the return code."""
|
|
465 |
if not callable(a_callable): |
|
466 |
raise ValueError("a_callable must be callable.") |
|
467 |
if stdin is None: |
|
468 |
stdin = StringIO("") |
|
469 |
if stdout is None: |
|
|
974.1.70
by Aaron Bentley
Fixed selftest spewage (Brian M. Carlson) |
470 |
if hasattr(self, "_log_file"): |
471 |
stdout = self._log_file |
|
472 |
else: |
|
473 |
stdout = StringIO() |
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
474 |
if stderr is None: |
|
974.1.70
by Aaron Bentley
Fixed selftest spewage (Brian M. Carlson) |
475 |
if hasattr(self, "_log_file"): |
476 |
stderr = self._log_file |
|
477 |
else: |
|
478 |
stderr = StringIO() |
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
479 |
real_stdin = sys.stdin |
480 |
real_stdout = sys.stdout |
|
481 |
real_stderr = sys.stderr |
|
482 |
try: |
|
483 |
sys.stdout = stdout |
|
484 |
sys.stderr = stderr |
|
485 |
sys.stdin = stdin |
|
|
1160
by Martin Pool
- tiny refactoring |
486 |
return a_callable(*args, **kwargs) |
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
487 |
finally: |
488 |
sys.stdout = real_stdout |
|
489 |
sys.stderr = real_stderr |
|
490 |
sys.stdin = real_stdin |
|
491 |
||
492 |
||
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
493 |
BzrTestBase = TestCase |
494 |
||
495 |
||
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
496 |
class TestCaseInTempDir(TestCase): |
497 |
"""Derived class that runs a test within a temporary directory. |
|
498 |
||
499 |
This is useful for tests that need to create a branch, etc.
|
|
500 |
||
501 |
The directory is created in a slightly complex way: for each
|
|
502 |
Python invocation, a new temporary top-level directory is created.
|
|
503 |
All test cases create their own directory within that. If the
|
|
504 |
tests complete successfully, the directory is removed.
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
505 |
|
506 |
InTempDir is an old alias for FunctionalTestCase.
|
|
507 |
"""
|
|
508 |
||
509 |
TEST_ROOT = None |
|
510 |
_TEST_NAME = 'test' |
|
511 |
OVERRIDE_PYTHON = 'python' |
|
512 |
||
513 |
def check_file_contents(self, filename, expect): |
|
514 |
self.log("check contents of file %s" % filename) |
|
515 |
contents = file(filename, 'r').read() |
|
516 |
if contents != expect: |
|
517 |
self.log("expected: %r" % expect) |
|
518 |
self.log("actually: %r" % contents) |
|
|
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
519 |
self.fail("contents of %s not as expected" % filename) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
520 |
|
521 |
def _make_test_root(self): |
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
522 |
if TestCaseInTempDir.TEST_ROOT is not None: |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
523 |
return
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
524 |
i = 0 |
525 |
while True: |
|
|
1185.16.147
by Martin Pool
[patch] Test base directory must be unicode (from Alexander) |
526 |
root = u'test%04d.tmp' % i |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
527 |
try: |
528 |
os.mkdir(root) |
|
529 |
except OSError, e: |
|
530 |
if e.errno == errno.EEXIST: |
|
531 |
i += 1 |
|
532 |
continue
|
|
533 |
else: |
|
534 |
raise
|
|
535 |
# successfully created
|
|
|
1185.31.37
by John Arbash Meinel
Switched os.path.abspath and os.path.realpath to osutils.* (still passes on cygwin) |
536 |
TestCaseInTempDir.TEST_ROOT = osutils.abspath(root) |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
537 |
break
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
538 |
# make a fake bzr directory there to prevent any tests propagating
|
539 |
# up onto the source directory's real branch
|
|
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
540 |
os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr')) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
541 |
|
542 |
def setUp(self): |
|
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
543 |
super(TestCaseInTempDir, self).setUp() |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
544 |
self._make_test_root() |
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
545 |
_currentdir = os.getcwdu() |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
546 |
short_id = self.id().replace('bzrlib.tests.', '') \ |
|
1218
by Martin Pool
- fix up import |
547 |
.replace('__main__.', '') |
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
548 |
self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
549 |
os.mkdir(self.test_dir) |
550 |
os.chdir(self.test_dir) |
|
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
551 |
os.environ['HOME'] = self.test_dir |
|
1185.31.39
by John Arbash Meinel
Replacing os.getcwdu() with osutils.getcwd(), |
552 |
os.environ['APPDATA'] = self.test_dir |
|
1185.16.110
by mbp at sourcefrog
Refactor test setup/teardown into cleanup callbacks |
553 |
def _leaveDirectory(): |
554 |
os.chdir(_currentdir) |
|
555 |
self.addCleanup(_leaveDirectory) |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
556 |
|
|
1185.38.7
by John Arbash Meinel
Updated build_tree to use fixed line-endings for tests which read the file contents and compare |
557 |
def build_tree(self, shape, line_endings='native'): |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
558 |
"""Build a test tree according to a pattern. |
559 |
||
560 |
shape is a sequence of file specifications. If the final
|
|
561 |
character is '/', a directory is created.
|
|
562 |
||
563 |
This doesn't add anything to a branch.
|
|
|
1185.38.7
by John Arbash Meinel
Updated build_tree to use fixed line-endings for tests which read the file contents and compare |
564 |
:param line_endings: Either 'binary' or 'native'
|
565 |
in binary mode, exact contents are written
|
|
566 |
in native mode, the line endings match the
|
|
567 |
default platform endings.
|
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
568 |
"""
|
569 |
# XXX: It's OK to just create them using forward slashes on windows?
|
|
570 |
for name in shape: |
|
|
1185.16.145
by Martin Pool
Remove all assert statements from test cases. |
571 |
self.assert_(isinstance(name, basestring)) |
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
572 |
if name[-1] == '/': |
573 |
os.mkdir(name[:-1]) |
|
574 |
else: |
|
|
1185.38.7
by John Arbash Meinel
Updated build_tree to use fixed line-endings for tests which read the file contents and compare |
575 |
if line_endings == 'binary': |
576 |
f = file(name, 'wb') |
|
577 |
elif line_endings == 'native': |
|
578 |
f = file(name, 'wt') |
|
579 |
else: |
|
580 |
raise BzrError('Invalid line ending request %r' % (line_endings,)) |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
581 |
print >>f, "contents of", name |
582 |
f.close() |
|
583 |
||
|
1185.16.53
by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests |
584 |
def build_tree_contents(self, shape): |
|
1514
by Robert Collins
Unbreak self.build_tree_shape in tests. |
585 |
build_tree_contents(shape) |
|
1185.16.53
by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests |
586 |
|
|
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
587 |
def failUnlessExists(self, path): |
588 |
"""Fail unless path, which may be abs or relative, exists.""" |
|
|
1448
by Robert Collins
revert symlinks correctly |
589 |
self.failUnless(osutils.lexists(path)) |
|
1185.31.40
by John Arbash Meinel
Added osutils.mkdtemp() |
590 |
|
591 |
def failIfExists(self, path): |
|
592 |
"""Fail if path, which may be abs or relative, exists.""" |
|
593 |
self.failIf(osutils.lexists(path)) |
|
|
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
594 |
|
|
1442.1.70
by Robert Collins
Add assertFileEqual to TestCaseInTempDir. |
595 |
def assertFileEqual(self, content, path): |
596 |
"""Fail if path does not contain 'content'.""" |
|
597 |
self.failUnless(osutils.lexists(path)) |
|
598 |
self.assertEqualDiff(content, open(path, 'r').read()) |
|
|
1185.31.40
by John Arbash Meinel
Added osutils.mkdtemp() |
599 |
|
|
1123
by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest |
600 |
|
|
1393.1.46
by Martin Pool
- bzr selftest arguments can be partial ids of tests to run |
601 |
def filter_suite_by_re(suite, pattern): |
|
1185.33.74
by Martin Pool
pychecker cleanups |
602 |
result = TestSuite() |
|
1393.1.46
by Martin Pool
- bzr selftest arguments can be partial ids of tests to run |
603 |
filter_re = re.compile(pattern) |
604 |
for test in iter_suite_tests(suite): |
|
|
1185.1.57
by Robert Collins
nuke --pattern to selftest, replace with regexp.search calls. |
605 |
if filter_re.search(test.id()): |
|
1393.1.46
by Martin Pool
- bzr selftest arguments can be partial ids of tests to run |
606 |
result.addTest(test) |
607 |
return result |
|
608 |
||
609 |
||
|
1185.16.58
by mbp at sourcefrog
- run all selftests by default |
610 |
def run_suite(suite, name='test', verbose=False, pattern=".*", |
|
1185.35.20
by Aaron Bentley
Only keep test failure directories if --keep-output is specified |
611 |
stop_on_failure=False, keep_output=False): |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
612 |
TestCaseInTempDir._TEST_NAME = name |
613 |
if verbose: |
|
614 |
verbosity = 2 |
|
615 |
else: |
|
616 |
verbosity = 1 |
|
617 |
runner = TextTestRunner(stream=sys.stdout, |
|
618 |
descriptions=0, |
|
619 |
verbosity=verbosity) |
|
|
1185.16.58
by mbp at sourcefrog
- run all selftests by default |
620 |
runner.stop_on_failure=stop_on_failure |
|
1393.1.46
by Martin Pool
- bzr selftest arguments can be partial ids of tests to run |
621 |
if pattern != '.*': |
622 |
suite = filter_suite_by_re(suite, pattern) |
|
623 |
result = runner.run(suite) |
|
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
624 |
# This is still a little bogus,
|
625 |
# but only a little. Folk not using our testrunner will
|
|
626 |
# have to delete their temp directories themselves.
|
|
|
1185.35.20
by Aaron Bentley
Only keep test failure directories if --keep-output is specified |
627 |
if result.wasSuccessful() or not keep_output: |
|
1393.1.6
by Martin Pool
- fold testsweet into bzrlib.selftest |
628 |
if TestCaseInTempDir.TEST_ROOT is not None: |
629 |
shutil.rmtree(TestCaseInTempDir.TEST_ROOT) |
|
630 |
else: |
|
631 |
print "Failed tests working directories are in '%s'\n" % TestCaseInTempDir.TEST_ROOT |
|
632 |
return result.wasSuccessful() |
|
633 |
||
634 |
||
|
1185.35.20
by Aaron Bentley
Only keep test failure directories if --keep-output is specified |
635 |
def selftest(verbose=False, pattern=".*", stop_on_failure=True, |
636 |
keep_output=False): |
|
|
1204
by Martin Pool
doc |
637 |
"""Run the whole test suite under the enhanced runner""" |
|
1185.16.58
by mbp at sourcefrog
- run all selftests by default |
638 |
return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern, |
|
1185.35.20
by Aaron Bentley
Only keep test failure directories if --keep-output is specified |
639 |
stop_on_failure=stop_on_failure, keep_output=keep_output) |
|
1092.1.17
by Robert Collins
remove TEST_CLASSES dead code and provide a bzrlib.test_suite() convenience method |
640 |
|
641 |
||
642 |
def test_suite(): |
|
|
1204
by Martin Pool
doc |
643 |
"""Build and return TestSuite for the whole program.""" |
|
721
by Martin Pool
- framework for running external commands from unittest suite |
644 |
from doctest import DocTestSuite |
645 |
||
|
1513
by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory. |
646 |
global MODULES_TO_DOCTEST |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
647 |
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
648 |
testmod_names = [ \ |
|
1518
by Robert Collins
Merge from mbp. |
649 |
'bzrlib.tests.test_ancestry', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
650 |
'bzrlib.tests.test_annotate', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
651 |
'bzrlib.tests.test_api', |
|
1518
by Robert Collins
Merge from mbp. |
652 |
'bzrlib.tests.test_bad_files', |
|
1185.50.21
by John Arbash Meinel
Added a test for basis-inventory, which should have happened before. |
653 |
'bzrlib.tests.test_basis_inventory', |
|
1518
by Robert Collins
Merge from mbp. |
654 |
'bzrlib.tests.test_branch', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
655 |
'bzrlib.tests.test_command', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
656 |
'bzrlib.tests.test_commit', |
657 |
'bzrlib.tests.test_commit_merge', |
|
658 |
'bzrlib.tests.test_config', |
|
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
659 |
'bzrlib.tests.test_conflicts', |
660 |
'bzrlib.tests.test_diff', |
|
661 |
'bzrlib.tests.test_fetch', |
|
|
1518
by Robert Collins
Merge from mbp. |
662 |
'bzrlib.tests.test_gpg', |
663 |
'bzrlib.tests.test_graph', |
|
664 |
'bzrlib.tests.test_hashcache', |
|
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
665 |
'bzrlib.tests.test_http', |
|
1518
by Robert Collins
Merge from mbp. |
666 |
'bzrlib.tests.test_identitymap', |
667 |
'bzrlib.tests.test_inv', |
|
668 |
'bzrlib.tests.test_log', |
|
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
669 |
'bzrlib.tests.test_merge', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
670 |
'bzrlib.tests.test_merge3', |
|
1518
by Robert Collins
Merge from mbp. |
671 |
'bzrlib.tests.test_merge_core', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
672 |
'bzrlib.tests.test_missing', |
|
1518
by Robert Collins
Merge from mbp. |
673 |
'bzrlib.tests.test_msgeditor', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
674 |
'bzrlib.tests.test_nonascii', |
|
1518
by Robert Collins
Merge from mbp. |
675 |
'bzrlib.tests.test_options', |
|
1185.50.20
by John Arbash Meinel
merge permissions branch, also fixup tests so they are lined up with bzr.dev to help prevent conflicts. |
676 |
'bzrlib.tests.test_osutils', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
677 |
'bzrlib.tests.test_parent', |
|
1185.58.1
by John Arbash Meinel
Added new permissions test (currently don't pass) |
678 |
'bzrlib.tests.test_permissions', |
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
679 |
'bzrlib.tests.test_plugins', |
|
1185.33.92
by Martin Pool
[patch] fix for 'bzr rm -v' (Wouter van Heyst) |
680 |
'bzrlib.tests.test_remove', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
681 |
'bzrlib.tests.test_revision', |
682 |
'bzrlib.tests.test_revision_info', |
|
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
683 |
'bzrlib.tests.test_revisionnamespaces', |
|
1518
by Robert Collins
Merge from mbp. |
684 |
'bzrlib.tests.test_revprops', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
685 |
'bzrlib.tests.test_reweave', |
|
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
686 |
'bzrlib.tests.test_rio', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
687 |
'bzrlib.tests.test_sampler', |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
688 |
'bzrlib.tests.test_selftest', |
|
1185.33.89
by Martin Pool
[patch] add a selftest test that the setup build script works (Alexander Belchenko) |
689 |
'bzrlib.tests.test_setup', |
|
1185.50.20
by John Arbash Meinel
merge permissions branch, also fixup tests so they are lined up with bzr.dev to help prevent conflicts. |
690 |
'bzrlib.tests.test_sftp_transport', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
691 |
'bzrlib.tests.test_smart_add', |
|
1522
by Robert Collins
Test for the number of uses of self.working_tree() in branch.py |
692 |
'bzrlib.tests.test_source', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
693 |
'bzrlib.tests.test_status', |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
694 |
'bzrlib.tests.test_store', |
|
1518
by Robert Collins
Merge from mbp. |
695 |
'bzrlib.tests.test_testament', |
696 |
'bzrlib.tests.test_trace', |
|
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
697 |
'bzrlib.tests.test_transactions', |
698 |
'bzrlib.tests.test_transport', |
|
699 |
'bzrlib.tests.test_tsort', |
|
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
700 |
'bzrlib.tests.test_ui', |
701 |
'bzrlib.tests.test_uncommit', |
|
702 |
'bzrlib.tests.test_upgrade', |
|
703 |
'bzrlib.tests.test_weave', |
|
704 |
'bzrlib.tests.test_whitebox', |
|
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
705 |
'bzrlib.tests.test_workingtree', |
|
1185.33.91
by Martin Pool
[merge] improved 'missing' command from aaron |
706 |
'bzrlib.tests.test_xml', |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
707 |
]
|
708 |
||
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
709 |
TestCase.BZRPATH = osutils.pathjoin( |
710 |
osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr') |
|
|
1185.31.57
by John Arbash Meinel
[merge] bzr.dev |
711 |
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0])) |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
712 |
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0]) |
|
744
by Martin Pool
- show nicer descriptions while running tests |
713 |
print
|
|
721
by Martin Pool
- framework for running external commands from unittest suite |
714 |
suite = TestSuite() |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
715 |
# python2.4's TestLoader.loadTestsFromNames gives very poor
|
716 |
# errors if it fails to load a named module - no indication of what's
|
|
717 |
# actually wrong, just "no such module". We should probably override that
|
|
718 |
# class, but for the moment just load them ourselves. (mbp 20051202)
|
|
719 |
loader = TestLoader() |
|
720 |
for mod_name in testmod_names: |
|
721 |
mod = _load_module_by_name(mod_name) |
|
722 |
suite.addTest(loader.loadTestsFromModule(mod)) |
|
|
1513
by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory. |
723 |
for package in packages_to_test(): |
724 |
suite.addTest(package.test_suite()) |
|
|
855
by Martin Pool
- Patch from John to allow plugins to add their own tests. |
725 |
for m in MODULES_TO_TEST: |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
726 |
suite.addTest(loader.loadTestsFromModule(m)) |
|
855
by Martin Pool
- Patch from John to allow plugins to add their own tests. |
727 |
for m in (MODULES_TO_DOCTEST): |
|
721
by Martin Pool
- framework for running external commands from unittest suite |
728 |
suite.addTest(DocTestSuite(m)) |
|
1516
by Robert Collins
* bzrlib.plugin.all_plugins has been changed from an attribute to a |
729 |
for name, plugin in bzrlib.plugin.all_plugins().items(): |
730 |
if hasattr(plugin, 'test_suite'): |
|
731 |
suite.addTest(plugin.test_suite()) |
|
|
1092.1.17
by Robert Collins
remove TEST_CLASSES dead code and provide a bzrlib.test_suite() convenience method |
732 |
return suite |
|
764
by Martin Pool
- log messages from a particular test are printed if that test fails |
733 |
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
734 |
|
735 |
def _load_module_by_name(mod_name): |
|
736 |
parts = mod_name.split('.') |
|
737 |
module = __import__(mod_name) |
|
738 |
del parts[0] |
|
739 |
# for historical reasons python returns the top-level module even though
|
|
740 |
# it loads the submodule; we need to walk down to get the one we want.
|
|
741 |
while parts: |
|
742 |
module = getattr(module, parts.pop(0)) |
|
743 |
return module |