290
290
for test, err in errors:
291
291
self.stream.writeln(self.separator1)
292
292
self.stream.write("%s: " % flavour)
293
if self.use_numbered_dirs:
294
294
self.stream.write('#%d ' % test.number)
295
295
self.stream.writeln(self.getDescription(test))
296
296
if getattr(test, '_get_log', None) is not None:
320
320
bench_history=None,
323
use_numbered_dirs=False,
324
325
ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
325
bench_history, num_tests)
326
bench_history, num_tests, use_numbered_dirs)
327
328
self.pb = self.ui.nested_progress_bar()
328
329
self._supplied_pb = False
364
365
+ self._shortened_test_description(test))
366
367
def _test_description(self, test):
368
if self.use_numbered_dirs:
368
369
return '#%d %s' % (self.count,
369
370
self._shortened_test_description(test))
433
434
# width needs space for 6 char status, plus 1 for slash, plus 2 10-char
434
435
# numbers, plus a trailing blank
435
436
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
437
if self.use_numbered_dirs:
437
438
self.stream.write('%5d ' % self.count)
438
439
self.stream.write(self._ellipsize_to_right(name,
439
440
osutils.terminal_width()-36))
495
496
keep_output=False,
498
use_numbered_dirs=False,
497
500
self.stream = unittest._WritelnDecorator(stream)
498
501
self.descriptions = descriptions
499
502
self.verbosity = verbosity
500
503
self.keep_output = keep_output
501
504
self._bench_history = bench_history
505
self.use_numbered_dirs = use_numbered_dirs
503
507
def run(self, test):
504
508
"Run the given test case or test suite."
513
517
bench_history=self._bench_history,
514
518
num_tests=test.countTestCases(),
519
use_numbered_dirs=self.use_numbered_dirs,
516
521
result.stop_early = self.stop_on_failure
517
522
result.report_starting()
571
576
test_root = test_root.encode(
572
577
sys.getfilesystemencoding())
574
osutils.rmtree(test_root)
576
if sys.platform == 'win32' and e.errno == errno.EACCES:
577
print >>sys.stderr, ('Permission denied: '
578
'unable to remove testing dir '
579
'%s' % os.path.basename(test_root))
578
_rmtree_temp_dir(test_root)
583
580
note("Failed tests working directories are in '%s'\n", test_root)
584
581
TestCaseWithMemoryTransport.TEST_ROOT = None
755
752
self._benchcalls = []
756
753
self._benchtime = None
757
754
# prevent hooks affecting tests
758
self._preserved_hooks = bzrlib.branch.Branch.hooks
755
self._preserved_hooks = {
756
bzrlib.branch.Branch:bzrlib.branch.Branch.hooks,
757
bzrlib.smart.server.SmartTCPServer:bzrlib.smart.server.SmartTCPServer.hooks,
759
759
self.addCleanup(self._restoreHooks)
760
760
# this list of hooks must be kept in sync with the defaults
920
920
self.fail("%r is an instance of %s rather than %s" % (
921
921
obj, obj.__class__, kls))
923
def expectFailure(self, reason, assertion, *args, **kwargs):
924
"""Invoke a test, expecting it to fail for the given reason.
926
This is for assertions that ought to succeed, but currently fail.
927
(The failure is *expected* but not *wanted*.) Please be very precise
928
about the failure you're expecting. If a new bug is introduced,
929
AssertionError should be raised, not KnownFailure.
931
Frequently, expectFailure should be followed by an opposite assertion.
934
Intended to be used with a callable that raises AssertionError as the
935
'assertion' parameter. args and kwargs are passed to the 'assertion'.
937
Raises KnownFailure if the test fails. Raises AssertionError if the
942
self.expectFailure('Math is broken', self.assertNotEqual, 54,
944
self.assertEqual(42, dynamic_val)
946
This means that a dynamic_val of 54 will cause the test to raise
947
a KnownFailure. Once math is fixed and the expectFailure is removed,
948
only a dynamic_val of 42 will allow the test to pass. Anything other
949
than 54 or 42 will cause an AssertionError.
952
assertion(*args, **kwargs)
953
except AssertionError:
954
raise KnownFailure(reason)
956
self.fail('Unexpected success. Should have failed: %s' % reason)
923
958
def _capture_warnings(self, a_callable, *args, **kwargs):
924
959
"""A helper for callDeprecated and applyDeprecated.
1063
1098
osutils.set_or_unset_env(name, value)
1065
1100
def _restoreHooks(self):
1066
bzrlib.branch.Branch.hooks = self._preserved_hooks
1101
for klass, hooks in self._preserved_hooks.items():
1102
setattr(klass, 'hooks', hooks)
1068
1104
def knownFailure(self, reason):
1069
1105
"""This test has failed for some known reason."""
1800
1836
OVERRIDE_PYTHON = 'python'
1837
use_numbered_dirs = False
1802
1839
def check_file_contents(self, filename, expect):
1803
1840
self.log("check contents of file %s" % filename)
1813
1850
For TestCaseInTempDir we create a temporary directory based on the test
1814
1851
name and then create two subdirs - test and home under it.
1816
if NUMBERED_DIRS: # strongly recommended on Windows
1817
# due the path length limitation (260 chars)
1853
if self.use_numbered_dirs: # strongly recommended on Windows
1854
# due the path length limitation (260 ch.)
1818
1855
candidate_dir = '%s/%dK/%05d' % (self.TEST_ROOT,
1819
1856
int(self.number/1000),
2043
2080
transport=None, lsprof_timed=None, bench_history=None,
2044
2081
matching_tests_first=None,
2045
2082
numbered_dirs=None):
2046
global NUMBERED_DIRS
2083
use_numbered_dirs = bool(numbered_dirs)
2085
TestCase._gather_lsprof_in_benchmarks = lsprof_timed
2047
2086
if numbered_dirs is not None:
2048
NUMBERED_DIRS = bool(numbered_dirs)
2050
TestCase._gather_lsprof_in_benchmarks = lsprof_timed
2087
TestCaseInTempDir.use_numbered_dirs = use_numbered_dirs
2056
2093
descriptions=0,
2057
2094
verbosity=verbosity,
2058
2095
keep_output=keep_output,
2059
bench_history=bench_history)
2096
bench_history=bench_history,
2097
use_numbered_dirs=use_numbered_dirs,
2060
2099
runner.stop_on_failure=stop_on_failure
2061
2100
if pattern != '.*':
2062
2101
if matching_tests_first:
2261
2300
suite.addTests(adapter.adapt(test))
2303
def _rmtree_temp_dir(dirname):
2305
osutils.rmtree(dirname)
2307
if sys.platform == 'win32' and e.errno == errno.EACCES:
2308
print >>sys.stderr, ('Permission denied: '
2309
'unable to remove testing dir '
2310
'%s' % os.path.basename(test_root))
2264
2315
def clean_selftest_output(root=None, quiet=False):
2265
2316
"""Remove all selftest output directories from root directory.