89
90
from bzrlib.tests.treeshape import build_tree_contents
90
91
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
93
# Mark this python module as being part of the implementation
94
# of unittest: this gives us better tracebacks where the last
95
# shown frame is the test code, not our assertXYZ.
92
98
default_transport = LocalURLServer
94
100
MODULES_TO_TEST = []
503
510
self.keep_output = keep_output
504
511
self._bench_history = bench_history
505
512
self.use_numbered_dirs = use_numbered_dirs
513
self.list_only = list_only
507
515
def run(self, test):
508
516
"Run the given test case or test suite."
521
529
result.stop_early = self.stop_on_failure
522
530
result.report_starting()
532
if self.verbosity >= 2:
533
self.stream.writeln("Listing tests only ...\n")
535
for t in iter_suite_tests(test):
536
self.stream.writeln("%s" % (t.id()))
538
actionTaken = "Listed"
541
run = result.testsRun
524
543
stopTime = time.time()
525
544
timeTaken = stopTime - startTime
526
545
result.printErrors()
527
546
self.stream.writeln(result.separator2)
528
run = result.testsRun
529
self.stream.writeln("Ran %d test%s in %.3fs" %
530
(run, run != 1 and "s" or "", timeTaken))
547
self.stream.writeln("%s %d test%s in %.3fs" % (actionTaken,
548
run, run != 1 and "s" or "", timeTaken))
531
549
self.stream.writeln()
532
550
if not result.wasSuccessful():
533
551
self.stream.write("FAILED (")
1277
1295
self.log('errors:\n%r', err)
1278
1296
if retcode is not None:
1279
self.assertEquals(retcode, result)
1297
self.assertEquals(retcode, result,
1298
message='Unexpected return code')
1280
1299
return out, err
1282
1301
def run_bzr(self, *args, **kwargs):
1297
1316
encoding = kwargs.pop('encoding', None)
1298
1317
stdin = kwargs.pop('stdin', None)
1299
1318
working_dir = kwargs.pop('working_dir', None)
1300
return self.run_bzr_captured(args, retcode=retcode, encoding=encoding,
1301
stdin=stdin, working_dir=working_dir)
1319
error_regexes = kwargs.pop('error_regexes', [])
1321
out, err = self.run_bzr_captured(args, retcode=retcode,
1322
encoding=encoding, stdin=stdin, working_dir=working_dir)
1324
for regex in error_regexes:
1325
self.assertContainsRe(err, regex)
1303
1329
def run_bzr_decode(self, *args, **kwargs):
1304
1330
if 'encoding' in kwargs:
1331
1357
'commit', '--strict', '-m', 'my commit comment')
1333
1359
kwargs.setdefault('retcode', 3)
1334
out, err = self.run_bzr(*args, **kwargs)
1335
for regex in error_regexes:
1336
self.assertContainsRe(err, regex)
1360
out, err = self.run_bzr(error_regexes=error_regexes, *args, **kwargs)
1337
1361
return out, err
1339
1363
def run_bzr_subprocess(self, *args, **kwargs):
1935
1959
self.assertEqualDiff(content, s)
1937
1961
def failUnlessExists(self, path):
1938
"""Fail unless path, which may be abs or relative, exists."""
1939
self.failUnless(osutils.lexists(path),path+" does not exist")
1962
"""Fail unless path or paths, which may be abs or relative, exist."""
1963
if not isinstance(path, basestring):
1965
self.failUnlessExists(p)
1967
self.failUnless(osutils.lexists(path),path+" does not exist")
1941
1969
def failIfExists(self, path):
1942
"""Fail if path, which may be abs or relative, exists."""
1943
self.failIf(osutils.lexists(path),path+" exists")
1970
"""Fail if path or paths, which may be abs or relative, exist."""
1971
if not isinstance(path, basestring):
1973
self.failIfExists(p)
1975
self.failIf(osutils.lexists(path),path+" exists")
1977
def assertInWorkingTree(self,path,root_path='.',tree=None):
1978
"""Assert whether path or paths are in the WorkingTree"""
1980
tree = workingtree.WorkingTree.open(root_path)
1981
if not isinstance(path, basestring):
1983
self.assertInWorkingTree(p,tree=tree)
1985
self.assertIsNot(tree.path2id(path), None,
1986
path+' not in working tree.')
1988
def assertNotInWorkingTree(self,path,root_path='.',tree=None):
1989
"""Assert whether path or paths are not in the WorkingTree"""
1991
tree = workingtree.WorkingTree.open(root_path)
1992
if not isinstance(path, basestring):
1994
self.assertNotInWorkingTree(p,tree=tree)
1996
self.assertIs(tree.path2id(path), None, path+' in working tree.')
1946
1999
class TestCaseWithTransport(TestCaseInTempDir):
2048
2101
self.transport_readonly_server = HttpServer
2051
def filter_suite_by_re(suite, pattern):
2052
result = TestUtil.TestSuite()
2053
filter_re = re.compile(pattern)
2054
for test in iter_suite_tests(suite):
2055
if filter_re.search(test.id()):
2056
result.addTest(test)
2060
def sort_suite_by_re(suite, pattern):
2104
def filter_suite_by_re(suite, pattern, exclude_pattern=None,
2105
random_order=False):
2106
"""Create a test suite by filtering another one.
2108
:param suite: the source suite
2109
:param pattern: pattern that names must match
2110
:param exclude_pattern: pattern that names must not match, if any
2111
:param random_order: if True, tests in the new suite will be put in
2113
:returns: the newly created suite
2115
return sort_suite_by_re(suite, pattern, exclude_pattern,
2116
random_order, False)
2119
def sort_suite_by_re(suite, pattern, exclude_pattern=None,
2120
random_order=False, append_rest=True):
2121
"""Create a test suite by sorting another one.
2123
:param suite: the source suite
2124
:param pattern: pattern that names must match in order to go
2125
first in the new suite
2126
:param exclude_pattern: pattern that names must not match, if any
2127
:param random_order: if True, tests in the new suite will be put in
2129
:param append_rest: if False, pattern is a strict filter and not
2130
just an ordering directive
2131
:returns: the newly created suite
2063
2135
filter_re = re.compile(pattern)
2136
if exclude_pattern is not None:
2137
exclude_re = re.compile(exclude_pattern)
2064
2138
for test in iter_suite_tests(suite):
2065
if filter_re.search(test.id()):
2140
if exclude_pattern is None or not exclude_re.search(test_id):
2141
if filter_re.search(test_id):
2146
random.shuffle(first)
2147
random.shuffle(second)
2069
2148
return TestUtil.TestSuite(first + second)
2073
2152
stop_on_failure=False, keep_output=False,
2074
2153
transport=None, lsprof_timed=None, bench_history=None,
2075
2154
matching_tests_first=None,
2076
numbered_dirs=None):
2158
exclude_pattern=None,
2077
2160
use_numbered_dirs = bool(numbered_dirs)
2079
2162
TestCase._gather_lsprof_in_benchmarks = lsprof_timed
2089
2172
keep_output=keep_output,
2090
2173
bench_history=bench_history,
2091
2174
use_numbered_dirs=use_numbered_dirs,
2175
list_only=list_only,
2093
2177
runner.stop_on_failure=stop_on_failure
2178
# Initialise the random number generator and display the seed used.
2179
# We convert the seed to a long to make it reuseable across invocations.
2180
random_order = False
2181
if random_seed is not None:
2183
if random_seed == "now":
2184
random_seed = long(time.time())
2186
# Convert the seed to a long if we can
2188
random_seed = long(random_seed)
2191
runner.stream.writeln("Randomizing test order using seed %s\n" %
2193
random.seed(random_seed)
2194
# Customise the list of tests if requested
2195
if pattern != '.*' or exclude_pattern is not None or random_order:
2095
2196
if matching_tests_first:
2096
suite = sort_suite_by_re(suite, pattern)
2197
suite = sort_suite_by_re(suite, pattern, exclude_pattern,
2098
suite = filter_suite_by_re(suite, pattern)
2200
suite = filter_suite_by_re(suite, pattern, exclude_pattern,
2099
2202
result = runner.run(suite)
2100
2203
return result.wasSuccessful()
2131
2237
lsprof_timed=lsprof_timed,
2132
2238
bench_history=bench_history,
2133
2239
matching_tests_first=matching_tests_first,
2134
numbered_dirs=numbered_dirs)
2240
numbered_dirs=numbered_dirs,
2241
list_only=list_only,
2242
random_seed=random_seed,
2243
exclude_pattern=exclude_pattern)
2136
2245
default_transport = old_transport
2149
2258
'bzrlib.tests.test_atomicfile',
2150
2259
'bzrlib.tests.test_bad_files',
2151
2260
'bzrlib.tests.test_branch',
2261
'bzrlib.tests.test_bugtracker',
2152
2262
'bzrlib.tests.test_bundle',
2153
2263
'bzrlib.tests.test_bzrdir',
2154
2264
'bzrlib.tests.test_cache_utf8',
2161
2271
'bzrlib.tests.test_delta',
2162
2272
'bzrlib.tests.test_diff',
2163
2273
'bzrlib.tests.test_dirstate',
2164
'bzrlib.tests.test_doc_generate',
2165
2274
'bzrlib.tests.test_errors',
2166
2275
'bzrlib.tests.test_escaped_store',
2167
2276
'bzrlib.tests.test_extract',
2173
2282
'bzrlib.tests.test_gpg',
2174
2283
'bzrlib.tests.test_graph',
2175
2284
'bzrlib.tests.test_hashcache',
2285
'bzrlib.tests.test_help',
2176
2286
'bzrlib.tests.test_http',
2177
2287
'bzrlib.tests.test_http_response',
2178
2288
'bzrlib.tests.test_https_ca_bundle',
2203
2313
'bzrlib.tests.test_progress',
2204
2314
'bzrlib.tests.test_reconcile',
2205
2315
'bzrlib.tests.test_registry',
2316
'bzrlib.tests.test_remote',
2206
2317
'bzrlib.tests.test_repository',
2207
2318
'bzrlib.tests.test_revert',
2208
2319
'bzrlib.tests.test_revision',
2213
2324
'bzrlib.tests.test_selftest',
2214
2325
'bzrlib.tests.test_setup',
2215
2326
'bzrlib.tests.test_sftp_transport',
2327
'bzrlib.tests.test_smart',
2216
2328
'bzrlib.tests.test_smart_add',
2217
2329
'bzrlib.tests.test_smart_transport',
2218
2330
'bzrlib.tests.test_source',