105
109
default_transport = LocalURLServer
108
MODULES_TO_DOCTEST = [
121
def packages_to_test():
122
"""Return a list of packages to test.
124
The packages are not globally imported so that import failures are
125
triggered when running selftest, not when importing the command.
128
import bzrlib.tests.blackbox
129
import bzrlib.tests.branch_implementations
130
import bzrlib.tests.bzrdir_implementations
131
import bzrlib.tests.interrepository_implementations
132
import bzrlib.tests.interversionedfile_implementations
133
import bzrlib.tests.intertree_implementations
134
import bzrlib.tests.per_lock
135
import bzrlib.tests.repository_implementations
136
import bzrlib.tests.revisionstore_implementations
137
import bzrlib.tests.tree_implementations
138
import bzrlib.tests.workingtree_implementations
141
bzrlib.tests.blackbox,
142
bzrlib.tests.branch_implementations,
143
bzrlib.tests.bzrdir_implementations,
144
bzrlib.tests.interrepository_implementations,
145
bzrlib.tests.interversionedfile_implementations,
146
bzrlib.tests.intertree_implementations,
147
bzrlib.tests.per_lock,
148
bzrlib.tests.repository_implementations,
149
bzrlib.tests.revisionstore_implementations,
150
bzrlib.tests.tree_implementations,
151
bzrlib.tests.workingtree_implementations,
155
112
class ExtendedTestResult(unittest._TextTestResult):
156
113
"""Accepts, reports and accumulates the results of running tests.
158
Compared to this unittest version this class adds support for profiling,
159
benchmarking, stopping as soon as a test fails, and skipping tests.
160
There are further-specialized subclasses for different types of display.
115
Compared to the unittest version this class adds support for
116
profiling, benchmarking, stopping as soon as a test fails, and
117
skipping tests. There are further-specialized subclasses for
118
different types of display.
120
When a test finishes, in whatever way, it calls one of the addSuccess,
121
addFailure or addError classes. These in turn may redirect to a more
122
specific case for the special test results supported by our extended
125
Note that just one of these objects is fed the results from many tests.
163
128
stop_early = False
244
211
def addError(self, test, err):
245
self.extractBenchmarkTime(test)
246
self._cleanupLogFile(test)
212
"""Tell result that test finished with an error.
214
Called from the TestCase run() method when the test
215
fails with an unexpected error.
217
self._testConcluded(test)
247
218
if isinstance(err[1], TestSkipped):
248
return self.addSkipped(test, err)
219
return self._addSkipped(test, err)
249
220
elif isinstance(err[1], UnavailableFeature):
250
221
return self.addNotSupported(test, err[1].args[0])
251
unittest.TestResult.addError(self, test, err)
252
self.error_count += 1
253
self.report_error(test, err)
223
unittest.TestResult.addError(self, test, err)
224
self.error_count += 1
225
self.report_error(test, err)
228
self._cleanupLogFile(test)
257
230
def addFailure(self, test, err):
258
self._cleanupLogFile(test)
259
self.extractBenchmarkTime(test)
231
"""Tell result that test failed.
233
Called from the TestCase run() method when the test
234
fails because e.g. an assert() method failed.
236
self._testConcluded(test)
260
237
if isinstance(err[1], KnownFailure):
261
return self.addKnownFailure(test, err)
262
unittest.TestResult.addFailure(self, test, err)
263
self.failure_count += 1
264
self.report_failure(test, err)
268
def addKnownFailure(self, test, err):
238
return self._addKnownFailure(test, err)
240
unittest.TestResult.addFailure(self, test, err)
241
self.failure_count += 1
242
self.report_failure(test, err)
245
self._cleanupLogFile(test)
247
def addSuccess(self, test):
248
"""Tell result that test completed successfully.
250
Called from the TestCase run()
252
self._testConcluded(test)
253
if self._bench_history is not None:
254
benchmark_time = self._extractBenchmarkTime(test)
255
if benchmark_time is not None:
256
self._bench_history.write("%s %s\n" % (
257
self._formatTime(benchmark_time),
259
self.report_success(test)
260
self._cleanupLogFile(test)
261
unittest.TestResult.addSuccess(self, test)
262
test._log_contents = ''
264
def _testConcluded(self, test):
265
"""Common code when a test has finished.
267
Called regardless of whether it succeded, failed, etc.
271
def _addKnownFailure(self, test, err):
269
272
self.known_failure_count += 1
270
273
self.report_known_failure(test, err)
272
275
def addNotSupported(self, test, feature):
276
"""The test will not be run because of a missing feature.
278
# this can be called in two different ways: it may be that the
279
# test started running, and then raised (through addError)
280
# UnavailableFeature. Alternatively this method can be called
281
# while probing for features before running the tests; in that
282
# case we will see startTest and stopTest, but the test will never
273
284
self.unsupported.setdefault(str(feature), 0)
274
285
self.unsupported[str(feature)] += 1
275
286
self.report_unsupported(test, feature)
277
def addSuccess(self, test):
278
self.extractBenchmarkTime(test)
279
if self._bench_history is not None:
280
if self._benchmarkTime is not None:
281
self._bench_history.write("%s %s\n" % (
282
self._formatTime(self._benchmarkTime),
284
self.report_success(test)
285
unittest.TestResult.addSuccess(self, test)
287
def addSkipped(self, test, skip_excinfo):
288
self.report_skip(test, skip_excinfo)
289
# seems best to treat this as success from point-of-view of unittest
290
# -- it actually does nothing so it barely matters :)
288
def _addSkipped(self, test, skip_excinfo):
289
if isinstance(skip_excinfo[1], TestNotApplicable):
290
self.not_applicable_count += 1
291
self.report_not_applicable(test, skip_excinfo)
294
self.report_skip(test, skip_excinfo)
293
297
except KeyboardInterrupt:
296
self.addError(test, test.__exc_info())
300
self.addError(test, test._exc_info())
302
# seems best to treat this as success from point-of-view of unittest
303
# -- it actually does nothing so it barely matters :)
298
304
unittest.TestResult.addSuccess(self, test)
305
test._log_contents = ''
300
307
def printErrorList(self, flavour, errors):
301
308
for test, err in errors:
1219
1368
if not feature.available():
1220
1369
raise UnavailableFeature(feature)
1222
@deprecated_method(zero_eighteen)
1223
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
1225
"""Invoke bzr and return (stdout, stderr).
1227
Don't call this method, just use run_bzr() which is equivalent.
1229
:param argv: Arguments to invoke bzr. This may be either a
1230
single string, in which case it is split by shlex into words,
1231
or a list of arguments.
1232
:param retcode: Expected return code, or None for don't-care.
1233
:param encoding: Encoding for sys.stdout and sys.stderr
1234
:param stdin: A string to be used as stdin for the command.
1235
:param working_dir: Change to this directory before running
1237
return self._run_bzr_autosplit(argv, retcode=retcode,
1238
encoding=encoding, stdin=stdin, working_dir=working_dir,
1241
1371
def _run_bzr_autosplit(self, args, retcode, encoding, stdin,
1243
1373
"""Run bazaar command line, splitting up a string command line."""
1244
1374
if isinstance(args, basestring):
1245
args = list(shlex.split(args))
1375
# shlex don't understand unicode strings,
1376
# so args should be plain string (bialix 20070906)
1377
args = list(shlex.split(str(args)))
1246
1378
return self._run_bzr_core(args, retcode=retcode,
1247
1379
encoding=encoding, stdin=stdin, working_dir=working_dir,
1772
1906
base = self.get_vfs_only_server().get_url()
1773
1907
return self._adjust_url(base, relpath)
1909
def _create_safety_net(self):
1910
"""Make a fake bzr directory.
1912
This prevents any tests propagating up onto the TEST_ROOT directory's
1915
root = TestCaseWithMemoryTransport.TEST_ROOT
1916
bzrdir.BzrDir.create_standalone_workingtree(root)
1918
def _check_safety_net(self):
1919
"""Check that the safety .bzr directory have not been touched.
1921
_make_test_root have created a .bzr directory to prevent tests from
1922
propagating. This method ensures than a test did not leaked.
1924
root = TestCaseWithMemoryTransport.TEST_ROOT
1925
wt = workingtree.WorkingTree.open(root)
1926
last_rev = wt.last_revision()
1927
if last_rev != 'null:':
1928
# The current test have modified the /bzr directory, we need to
1929
# recreate a new one or all the followng tests will fail.
1930
# If you need to inspect its content uncomment the following line
1931
# import pdb; pdb.set_trace()
1932
_rmtree_temp_dir(root + '/.bzr')
1933
self._create_safety_net()
1934
raise AssertionError('%s/.bzr should not be modified' % root)
1775
1936
def _make_test_root(self):
1776
if TestCaseWithMemoryTransport.TEST_ROOT is not None:
1778
root = tempfile.mkdtemp(prefix='testbzr-', suffix='.tmp')
1779
TestCaseWithMemoryTransport.TEST_ROOT = root
1781
# make a fake bzr directory there to prevent any tests propagating
1782
# up onto the source directory's real branch
1783
bzrdir.BzrDir.create_standalone_workingtree(root)
1785
# The same directory is used by all tests, and we're not specifically
1786
# told when all tests are finished. This will do.
1787
atexit.register(_rmtree_temp_dir, root)
1937
if TestCaseWithMemoryTransport.TEST_ROOT is None:
1938
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
1939
TestCaseWithMemoryTransport.TEST_ROOT = root
1941
self._create_safety_net()
1943
# The same directory is used by all tests, and we're not
1944
# specifically told when all tests are finished. This will do.
1945
atexit.register(_rmtree_temp_dir, root)
1947
self.addCleanup(self._check_safety_net)
1789
1949
def makeAndChdirToTestDir(self):
1790
1950
"""Create a temporary directories for this one test.
1949
2134
def build_tree_contents(self, shape):
1950
2135
build_tree_contents(shape)
1952
def assertFileEqual(self, content, path):
1953
"""Fail if path does not contain 'content'."""
1954
self.failUnlessExists(path)
1955
f = file(path, 'rb')
1960
self.assertEqualDiff(content, s)
1962
def failUnlessExists(self, path):
1963
"""Fail unless path or paths, which may be abs or relative, exist."""
1964
if not isinstance(path, basestring):
1966
self.failUnlessExists(p)
1968
self.failUnless(osutils.lexists(path),path+" does not exist")
1970
def failIfExists(self, path):
1971
"""Fail if path or paths, which may be abs or relative, exist."""
1972
if not isinstance(path, basestring):
1974
self.failIfExists(p)
1976
self.failIf(osutils.lexists(path),path+" exists")
1978
def assertInWorkingTree(self,path,root_path='.',tree=None):
2137
def assertInWorkingTree(self, path, root_path='.', tree=None):
1979
2138
"""Assert whether path or paths are in the WorkingTree"""
1980
2139
if tree is None:
1981
2140
tree = workingtree.WorkingTree.open(root_path)
1982
2141
if not isinstance(path, basestring):
1984
self.assertInWorkingTree(p,tree=tree)
2143
self.assertInWorkingTree(p, tree=tree)
1986
2145
self.assertIsNot(tree.path2id(path), None,
1987
2146
path+' not in working tree.')
1989
def assertNotInWorkingTree(self,path,root_path='.',tree=None):
2148
def assertNotInWorkingTree(self, path, root_path='.', tree=None):
1990
2149
"""Assert whether path or paths are not in the WorkingTree"""
1991
2150
if tree is None:
1992
2151
tree = workingtree.WorkingTree.open(root_path)
2102
2268
self.transport_readonly_server = HttpServer
2105
def filter_suite_by_re(suite, pattern, exclude_pattern=None,
2106
random_order=False):
2107
"""Create a test suite by filtering another one.
2109
:param suite: the source suite
2110
:param pattern: pattern that names must match
2111
:param exclude_pattern: pattern that names must not match, if any
2112
:param random_order: if True, tests in the new suite will be put in
2114
:returns: the newly created suite
2116
return sort_suite_by_re(suite, pattern, exclude_pattern,
2117
random_order, False)
2120
def sort_suite_by_re(suite, pattern, exclude_pattern=None,
2121
random_order=False, append_rest=True):
2122
"""Create a test suite by sorting another one.
2124
:param suite: the source suite
2125
:param pattern: pattern that names must match in order to go
2126
first in the new suite
2127
:param exclude_pattern: pattern that names must not match, if any
2128
:param random_order: if True, tests in the new suite will be put in
2130
:param append_rest: if False, pattern is a strict filter and not
2131
just an ordering directive
2132
:returns: the newly created suite
2271
def condition_id_re(pattern):
2272
"""Create a condition filter which performs a re check on a test's id.
2274
:param pattern: A regular expression string.
2275
:return: A callable that returns True if the re matches.
2136
2277
filter_re = re.compile(pattern)
2137
if exclude_pattern is not None:
2138
exclude_re = re.compile(exclude_pattern)
2139
for test in iter_suite_tests(suite):
2278
def condition(test):
2140
2279
test_id = test.id()
2141
if exclude_pattern is None or not exclude_re.search(test_id):
2142
if filter_re.search(test_id):
2147
random.shuffle(first)
2148
random.shuffle(second)
2149
return TestUtil.TestSuite(first + second)
2280
return filter_re.search(test_id)
2284
def condition_isinstance(klass_or_klass_list):
2285
"""Create a condition filter which returns isinstance(param, klass).
2287
:return: A callable which when called with one parameter obj return the
2288
result of isinstance(obj, klass_or_klass_list).
2291
return isinstance(obj, klass_or_klass_list)
2295
def condition_id_in_list(id_list):
2296
"""Create a condition filter which verify that test's id in a list.
2298
:param id_list: A TestIdList object.
2299
:return: A callable that returns True if the test's id appears in the list.
2301
def condition(test):
2302
return id_list.includes(test.id())
2306
def condition_id_startswith(starts):
2307
"""Create a condition filter verifying that test's id starts with a string.
2309
:param starts: A list of string.
2310
:return: A callable that returns True if the test's id starts with one of
2313
def condition(test):
2314
for start in starts:
2315
if test.id().startswith(start):
2321
def exclude_tests_by_condition(suite, condition):
2322
"""Create a test suite which excludes some tests from suite.
2324
:param suite: The suite to get tests from.
2325
:param condition: A callable whose result evaluates True when called with a
2326
test case which should be excluded from the result.
2327
:return: A suite which contains the tests found in suite that fail
2331
for test in iter_suite_tests(suite):
2332
if not condition(test):
2334
return TestUtil.TestSuite(result)
2337
def filter_suite_by_condition(suite, condition):
2338
"""Create a test suite by filtering another one.
2340
:param suite: The source suite.
2341
:param condition: A callable whose result evaluates True when called with a
2342
test case which should be included in the result.
2343
:return: A suite which contains the tests found in suite that pass
2347
for test in iter_suite_tests(suite):
2350
return TestUtil.TestSuite(result)
2353
def filter_suite_by_re(suite, pattern):
2354
"""Create a test suite by filtering another one.
2356
:param suite: the source suite
2357
:param pattern: pattern that names must match
2358
:returns: the newly created suite
2360
condition = condition_id_re(pattern)
2361
result_suite = filter_suite_by_condition(suite, condition)
2365
def filter_suite_by_id_list(suite, test_id_list):
2366
"""Create a test suite by filtering another one.
2368
:param suite: The source suite.
2369
:param test_id_list: A list of the test ids to keep as strings.
2370
:returns: the newly created suite
2372
condition = condition_id_in_list(test_id_list)
2373
result_suite = filter_suite_by_condition(suite, condition)
2377
def filter_suite_by_id_startswith(suite, start):
2378
"""Create a test suite by filtering another one.
2380
:param suite: The source suite.
2381
:param start: A list of string the test id must start with one of.
2382
:returns: the newly created suite
2384
condition = condition_id_startswith(start)
2385
result_suite = filter_suite_by_condition(suite, condition)
2389
def exclude_tests_by_re(suite, pattern):
2390
"""Create a test suite which excludes some tests from suite.
2392
:param suite: The suite to get tests from.
2393
:param pattern: A regular expression string. Test ids that match this
2394
pattern will be excluded from the result.
2395
:return: A TestSuite that contains all the tests from suite without the
2396
tests that matched pattern. The order of tests is the same as it was in
2399
return exclude_tests_by_condition(suite, condition_id_re(pattern))
2402
def preserve_input(something):
2403
"""A helper for performing test suite transformation chains.
2405
:param something: Anything you want to preserve.
2411
def randomize_suite(suite):
2412
"""Return a new TestSuite with suite's tests in random order.
2414
The tests in the input suite are flattened into a single suite in order to
2415
accomplish this. Any nested TestSuites are removed to provide global
2418
tests = list(iter_suite_tests(suite))
2419
random.shuffle(tests)
2420
return TestUtil.TestSuite(tests)
2423
def split_suite_by_condition(suite, condition):
2424
"""Split a test suite into two by a condition.
2426
:param suite: The suite to split.
2427
:param condition: The condition to match on. Tests that match this
2428
condition are returned in the first test suite, ones that do not match
2429
are in the second suite.
2430
:return: A tuple of two test suites, where the first contains tests from
2431
suite matching the condition, and the second contains the remainder
2432
from suite. The order within each output suite is the same as it was in
2437
for test in iter_suite_tests(suite):
2439
matched.append(test)
2441
did_not_match.append(test)
2442
return TestUtil.TestSuite(matched), TestUtil.TestSuite(did_not_match)
2445
def split_suite_by_re(suite, pattern):
2446
"""Split a test suite into two by a regular expression.
2448
:param suite: The suite to split.
2449
:param pattern: A regular expression string. Test ids that match this
2450
pattern will be in the first test suite returned, and the others in the
2451
second test suite returned.
2452
:return: A tuple of two test suites, where the first contains tests from
2453
suite matching pattern, and the second contains the remainder from
2454
suite. The order within each output suite is the same as it was in
2457
return split_suite_by_condition(suite, condition_id_re(pattern))
2152
2460
def run_suite(suite, name='test', verbose=False, pattern=".*",
2231
2566
matching_tests_first=matching_tests_first,
2232
2567
list_only=list_only,
2233
2568
random_seed=random_seed,
2234
exclude_pattern=exclude_pattern)
2569
exclude_pattern=exclude_pattern,
2236
2572
default_transport = old_transport
2573
selftest_debug_flags = old_debug_flags
2576
def load_test_id_list(file_name):
2577
"""Load a test id list from a text file.
2579
The format is one test id by line. No special care is taken to impose
2580
strict rules, these test ids are used to filter the test suite so a test id
2581
that do not match an existing test will do no harm. This allows user to add
2582
comments, leave blank lines, etc.
2586
ftest = open(file_name, 'rt')
2588
if e.errno != errno.ENOENT:
2591
raise errors.NoSuchFile(file_name)
2593
for test_name in ftest.readlines():
2594
test_list.append(test_name.strip())
2599
def suite_matches_id_list(test_suite, id_list):
2600
"""Warns about tests not appearing or appearing more than once.
2602
:param test_suite: A TestSuite object.
2603
:param test_id_list: The list of test ids that should be found in
2606
:return: (absents, duplicates) absents is a list containing the test found
2607
in id_list but not in test_suite, duplicates is a list containing the
2608
test found multiple times in test_suite.
2610
When using a prefined test id list, it may occurs that some tests do not
2611
exist anymore or that some tests use the same id. This function warns the
2612
tester about potential problems in his workflow (test lists are volatile)
2613
or in the test suite itself (using the same id for several tests does not
2614
help to localize defects).
2616
# Build a dict counting id occurrences
2618
for test in iter_suite_tests(test_suite):
2620
tests[id] = tests.get(id, 0) + 1
2625
occurs = tests.get(id, 0)
2627
not_found.append(id)
2629
duplicates.append(id)
2631
return not_found, duplicates
2634
class TestIdList(object):
2635
"""Test id list to filter a test suite.
2637
Relying on the assumption that test ids are built as:
2638
<module>[.<class>.<method>][(<param>+)], <module> being in python dotted
2639
notation, this class offers methods to :
2640
- avoid building a test suite for modules not refered to in the test list,
2641
- keep only the tests listed from the module test suite.
2644
def __init__(self, test_id_list):
2645
# When a test suite needs to be filtered against us we compare test ids
2646
# for equality, so a simple dict offers a quick and simple solution.
2647
self.tests = dict().fromkeys(test_id_list, True)
2649
# While unittest.TestCase have ids like:
2650
# <module>.<class>.<method>[(<param+)],
2651
# doctest.DocTestCase can have ids like:
2654
# <module>.<function>
2655
# <module>.<class>.<method>
2657
# Since we can't predict a test class from its name only, we settle on
2658
# a simple constraint: a test id always begins with its module name.
2661
for test_id in test_id_list:
2662
parts = test_id.split('.')
2663
mod_name = parts.pop(0)
2664
modules[mod_name] = True
2666
mod_name += '.' + part
2667
modules[mod_name] = True
2668
self.modules = modules
2670
def refers_to(self, module_name):
2671
"""Is there tests for the module or one of its sub modules."""
2672
return self.modules.has_key(module_name)
2674
def includes(self, test_id):
2675
return self.tests.has_key(test_id)
2678
class TestPrefixAliasRegistry(registry.Registry):
2679
"""A registry for test prefix aliases.
2681
This helps implement shorcuts for the --starting-with selftest
2682
option. Overriding existing prefixes is not allowed but not fatal (a
2683
warning will be emitted).
2686
def register(self, key, obj, help=None, info=None,
2687
override_existing=False):
2688
"""See Registry.register.
2690
Trying to override an existing alias causes a warning to be emitted,
2691
not a fatal execption.
2694
super(TestPrefixAliasRegistry, self).register(
2695
key, obj, help=help, info=info, override_existing=False)
2697
actual = self.get(key)
2698
note('Test prefix alias %s is already used for %s, ignoring %s'
2699
% (key, actual, obj))
2701
def resolve_alias(self, id_start):
2702
"""Replace the alias by the prefix in the given string.
2704
Using an unknown prefix is an error to help catching typos.
2706
parts = id_start.split('.')
2708
parts[0] = self.get(parts[0])
2710
raise errors.BzrCommandError(
2711
'%s is not a known test prefix alias' % parts[0])
2712
return '.'.join(parts)
2715
test_prefix_alias_registry = TestPrefixAliasRegistry()
2716
"""Registry of test prefix aliases."""
2719
# This alias allows to detect typos ('bzrlin.') by making all valid test ids
2720
# appear prefixed ('bzrlib.' is "replaced" by 'bzrlib.').
2721
test_prefix_alias_registry.register('bzrlib', 'bzrlib')
2723
# Obvious higest levels prefixes, feel free to add your own via a plugin
2724
test_prefix_alias_registry.register('bd', 'bzrlib.doc')
2725
test_prefix_alias_registry.register('bu', 'bzrlib.utils')
2726
test_prefix_alias_registry.register('bt', 'bzrlib.tests')
2727
test_prefix_alias_registry.register('bb', 'bzrlib.tests.blackbox')
2728
test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
2731
def test_suite(keep_only=None, starting_with=None):
2240
2732
"""Build and return TestSuite for the whole of bzrlib.
2734
:param keep_only: A list of test ids limiting the suite returned.
2736
:param starting_with: An id limiting the suite returned to the tests
2242
2739
This function can be replaced if you need to change the default test
2243
2740
suite on a global basis, but it is not encouraged.
2245
2742
testmod_names = [
2246
2744
'bzrlib.util.tests.test_bencode',
2745
'bzrlib.tests.blackbox',
2746
'bzrlib.tests.branch_implementations',
2747
'bzrlib.tests.bzrdir_implementations',
2748
'bzrlib.tests.commands',
2749
'bzrlib.tests.inventory_implementations',
2750
'bzrlib.tests.interrepository_implementations',
2751
'bzrlib.tests.intertree_implementations',
2752
'bzrlib.tests.per_lock',
2753
'bzrlib.tests.repository_implementations',
2754
'bzrlib.tests.test__dirstate_helpers',
2247
2755
'bzrlib.tests.test_ancestry',
2248
2756
'bzrlib.tests.test_annotate',
2249
2757
'bzrlib.tests.test_api',
2250
2758
'bzrlib.tests.test_atomicfile',
2251
2759
'bzrlib.tests.test_bad_files',
2760
'bzrlib.tests.test_bisect_multi',
2252
2761
'bzrlib.tests.test_branch',
2253
2762
'bzrlib.tests.test_branchbuilder',
2763
'bzrlib.tests.test_btree_index',
2254
2764
'bzrlib.tests.test_bugtracker',
2255
2765
'bzrlib.tests.test_bundle',
2256
2766
'bzrlib.tests.test_bzrdir',
2257
2767
'bzrlib.tests.test_cache_utf8',
2768
'bzrlib.tests.test_chunk_writer',
2258
2769
'bzrlib.tests.test_commands',
2259
2770
'bzrlib.tests.test_commit',
2260
2771
'bzrlib.tests.test_commit_merge',
2261
2772
'bzrlib.tests.test_config',
2262
2773
'bzrlib.tests.test_conflicts',
2263
'bzrlib.tests.test_pack',
2264
2774
'bzrlib.tests.test_counted_lock',
2265
2775
'bzrlib.tests.test_decorators',
2266
2776
'bzrlib.tests.test_delta',
2267
2777
'bzrlib.tests.test_deprecated_graph',
2268
2778
'bzrlib.tests.test_diff',
2269
2779
'bzrlib.tests.test_dirstate',
2780
'bzrlib.tests.test_directory_service',
2781
'bzrlib.tests.test_email_message',
2270
2782
'bzrlib.tests.test_errors',
2271
'bzrlib.tests.test_escaped_store',
2272
2783
'bzrlib.tests.test_extract',
2273
2784
'bzrlib.tests.test_fetch',
2274
2785
'bzrlib.tests.test_ftp_transport',
2301
2816
'bzrlib.tests.test_merge_directive',
2302
2817
'bzrlib.tests.test_missing',
2303
2818
'bzrlib.tests.test_msgeditor',
2819
'bzrlib.tests.test_multiparent',
2820
'bzrlib.tests.test_mutabletree',
2304
2821
'bzrlib.tests.test_nonascii',
2305
2822
'bzrlib.tests.test_options',
2306
2823
'bzrlib.tests.test_osutils',
2307
2824
'bzrlib.tests.test_osutils_encodings',
2825
'bzrlib.tests.test_pack',
2826
'bzrlib.tests.test_pack_repository',
2308
2827
'bzrlib.tests.test_patch',
2309
2828
'bzrlib.tests.test_patches',
2310
2829
'bzrlib.tests.test_permissions',
2311
2830
'bzrlib.tests.test_plugins',
2312
2831
'bzrlib.tests.test_progress',
2832
'bzrlib.tests.test_read_bundle',
2833
'bzrlib.tests.test_reconfigure',
2313
2834
'bzrlib.tests.test_reconcile',
2314
2835
'bzrlib.tests.test_registry',
2315
2836
'bzrlib.tests.test_remote',
2316
2837
'bzrlib.tests.test_repository',
2838
'bzrlib.tests.per_repository_reference',
2317
2839
'bzrlib.tests.test_revert',
2318
2840
'bzrlib.tests.test_revision',
2319
'bzrlib.tests.test_revisionnamespaces',
2841
'bzrlib.tests.test_revisionspec',
2320
2842
'bzrlib.tests.test_revisiontree',
2321
2843
'bzrlib.tests.test_rio',
2844
'bzrlib.tests.test_rules',
2322
2845
'bzrlib.tests.test_sampler',
2323
2846
'bzrlib.tests.test_selftest',
2324
2847
'bzrlib.tests.test_setup',
2343
2867
'bzrlib.tests.test_transactions',
2344
2868
'bzrlib.tests.test_transform',
2345
2869
'bzrlib.tests.test_transport',
2870
'bzrlib.tests.test_transport_implementations',
2871
'bzrlib.tests.test_transport_log',
2346
2872
'bzrlib.tests.test_tree',
2347
2873
'bzrlib.tests.test_treebuilder',
2348
2874
'bzrlib.tests.test_tsort',
2349
2875
'bzrlib.tests.test_tuned_gzip',
2350
2876
'bzrlib.tests.test_ui',
2877
'bzrlib.tests.test_uncommit',
2351
2878
'bzrlib.tests.test_upgrade',
2879
'bzrlib.tests.test_upgrade_stacked',
2352
2880
'bzrlib.tests.test_urlutils',
2353
2881
'bzrlib.tests.test_versionedfile',
2354
2882
'bzrlib.tests.test_version',
2355
2883
'bzrlib.tests.test_version_info',
2884
'bzrlib.tests.test__walkdirs_win32',
2356
2885
'bzrlib.tests.test_weave',
2357
2886
'bzrlib.tests.test_whitebox',
2887
'bzrlib.tests.test_win32utils',
2358
2888
'bzrlib.tests.test_workingtree',
2359
2889
'bzrlib.tests.test_workingtree_4',
2360
2890
'bzrlib.tests.test_wsgi',
2361
2891
'bzrlib.tests.test_xml',
2892
'bzrlib.tests.tree_implementations',
2893
'bzrlib.tests.workingtree_implementations',
2363
test_transport_implementations = [
2364
'bzrlib.tests.test_transport_implementations',
2365
'bzrlib.tests.test_read_bundle',
2367
suite = TestUtil.TestSuite()
2368
2896
loader = TestUtil.TestLoader()
2899
starting_with = [test_prefix_alias_registry.resolve_alias(start)
2900
for start in starting_with]
2901
# We take precedence over keep_only because *at loading time* using
2902
# both options means we will load less tests for the same final result.
2903
def interesting_module(name):
2904
for start in starting_with:
2906
# Either the module name starts with the specified string
2907
name.startswith(start)
2908
# or it may contain tests starting with the specified string
2909
or start.startswith(name)
2913
loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2915
elif keep_only is not None:
2916
id_filter = TestIdList(keep_only)
2917
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2918
def interesting_module(name):
2919
return id_filter.refers_to(name)
2922
loader = TestUtil.TestLoader()
2923
def interesting_module(name):
2924
# No filtering, all modules are interesting
2927
suite = loader.suiteClass()
2929
# modules building their suite with loadTestsFromModuleNames
2369
2930
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2370
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2371
adapter = TransportTestProviderAdapter()
2372
adapt_modules(test_transport_implementations, adapter, loader, suite)
2373
for package in packages_to_test():
2374
suite.addTest(package.test_suite())
2375
for m in MODULES_TO_TEST:
2376
suite.addTest(loader.loadTestsFromModule(m))
2377
for m in MODULES_TO_DOCTEST:
2932
modules_to_doctest = [
2937
'bzrlib.iterablefile',
2942
'bzrlib.symbol_versioning',
2945
'bzrlib.version_info_formats.format_custom',
2948
for mod in modules_to_doctest:
2949
if not interesting_module(mod):
2950
# No tests to keep here, move along
2379
suite.addTest(doctest.DocTestSuite(m))
2953
doc_suite = doctest.DocTestSuite(mod)
2380
2954
except ValueError, e:
2381
print '**failed to get doctest for: %s\n%s' %(m,e)
2955
print '**failed to get doctest for: %s\n%s' % (mod, e)
2383
for name, plugin in bzrlib.plugin.all_plugins().items():
2384
if getattr(plugin, 'test_suite', None) is not None:
2385
default_encoding = sys.getdefaultencoding()
2387
plugin_suite = plugin.test_suite()
2388
except ImportError, e:
2389
bzrlib.trace.warning(
2390
'Unable to test plugin "%s": %s', name, e)
2392
suite.addTest(plugin_suite)
2393
if default_encoding != sys.getdefaultencoding():
2394
bzrlib.trace.warning(
2395
'Plugin "%s" tried to reset default encoding to: %s', name,
2396
sys.getdefaultencoding())
2398
sys.setdefaultencoding(default_encoding)
2957
suite.addTest(doc_suite)
2959
default_encoding = sys.getdefaultencoding()
2960
for name, plugin in bzrlib.plugin.plugins().items():
2961
if not interesting_module(plugin.module.__name__):
2963
plugin_suite = plugin.test_suite()
2964
# We used to catch ImportError here and turn it into just a warning,
2965
# but really if you don't have --no-plugins this should be a failure.
2966
# mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
2967
if plugin_suite is None:
2968
plugin_suite = plugin.load_plugin_tests(loader)
2969
if plugin_suite is not None:
2970
suite.addTest(plugin_suite)
2971
if default_encoding != sys.getdefaultencoding():
2972
bzrlib.trace.warning(
2973
'Plugin "%s" tried to reset default encoding to: %s', name,
2974
sys.getdefaultencoding())
2976
sys.setdefaultencoding(default_encoding)
2979
suite = filter_suite_by_id_startswith(suite, starting_with)
2981
if keep_only is not None:
2982
# Now that the referred modules have loaded their tests, keep only the
2984
suite = filter_suite_by_id_list(suite, id_filter)
2985
# Do some sanity checks on the id_list filtering
2986
not_found, duplicates = suite_matches_id_list(suite, keep_only)
2988
# The tester has used both keep_only and starting_with, so he is
2989
# already aware that some tests are excluded from the list, there
2990
# is no need to tell him which.
2993
# Some tests mentioned in the list are not in the test suite. The
2994
# list may be out of date, report to the tester.
2995
for id in not_found:
2996
bzrlib.trace.warning('"%s" not found in the test suite', id)
2997
for id in duplicates:
2998
bzrlib.trace.warning('"%s" is used as an id by several tests', id)
3003
def multiply_tests_from_modules(module_name_list, scenario_iter, loader=None):
3004
"""Adapt all tests in some given modules to given scenarios.
3006
This is the recommended public interface for test parameterization.
3007
Typically the test_suite() method for a per-implementation test
3008
suite will call multiply_tests_from_modules and return the
3011
:param module_name_list: List of fully-qualified names of test
3013
:param scenario_iter: Iterable of pairs of (scenario_name,
3014
scenario_param_dict).
3015
:param loader: If provided, will be used instead of a new
3016
bzrlib.tests.TestLoader() instance.
3018
This returns a new TestSuite containing the cross product of
3019
all the tests in all the modules, each repeated for each scenario.
3020
Each test is adapted by adding the scenario name at the end
3021
of its name, and updating the test object's __dict__ with the
3022
scenario_param_dict.
3024
>>> r = multiply_tests_from_modules(
3025
... ['bzrlib.tests.test_sampler'],
3026
... [('one', dict(param=1)),
3027
... ('two', dict(param=2))])
3028
>>> tests = list(iter_suite_tests(r))
3032
'bzrlib.tests.test_sampler.DemoTest.test_nothing(one)'
3038
# XXX: Isn't load_tests() a better way to provide the same functionality
3039
# without forcing a predefined TestScenarioApplier ? --vila 080215
3041
loader = TestUtil.TestLoader()
3043
suite = loader.suiteClass()
3045
adapter = TestScenarioApplier()
3046
adapter.scenarios = list(scenario_iter)
3047
adapt_modules(module_name_list, adapter, loader, suite)
3051
def multiply_scenarios(scenarios_left, scenarios_right):
3052
"""Multiply two sets of scenarios.
3054
:returns: the cartesian product of the two sets of scenarios, that is
3055
a scenario for every possible combination of a left scenario and a
3059
('%s,%s' % (left_name, right_name),
3060
dict(left_dict.items() + right_dict.items()))
3061
for left_name, left_dict in scenarios_left
3062
for right_name, right_dict in scenarios_right]
2402
3066
def adapt_modules(mods_list, adapter, loader, suite):
2403
3067
"""Adapt the modules in mods_list using adapter and add to suite."""
2404
for test in iter_suite_tests(loader.loadTestsFromModuleNames(mods_list)):
3068
tests = loader.loadTestsFromModuleNames(mods_list)
3069
adapt_tests(tests, adapter, suite)
3072
def adapt_tests(tests_list, adapter, suite):
3073
"""Adapt the tests in tests_list using adapter and add to suite."""
3074
for test in iter_suite_tests(tests_list):
2405
3075
suite.addTests(adapter.adapt(test))
2483
3210
new_id = "%s(%s)" % (new_test.id(), scenario[0])
2484
3211
new_test.id = lambda: new_id
2485
3212
return new_test
3215
def probe_unicode_in_user_encoding():
3216
"""Try to encode several unicode strings to use in unicode-aware tests.
3217
Return first successfull match.
3219
:return: (unicode value, encoded plain string value) or (None, None)
3221
possible_vals = [u'm\xb5', u'\xe1', u'\u0410']
3222
for uni_val in possible_vals:
3224
str_val = uni_val.encode(bzrlib.user_encoding)
3225
except UnicodeEncodeError:
3226
# Try a different character
3229
return uni_val, str_val
3233
def probe_bad_non_ascii(encoding):
3234
"""Try to find [bad] character with code [128..255]
3235
that cannot be decoded to unicode in some encoding.
3236
Return None if all non-ascii characters is valid
3239
for i in xrange(128, 256):
3242
char.decode(encoding)
3243
except UnicodeDecodeError:
3248
class _FTPServerFeature(Feature):
3249
"""Some tests want an FTP Server, check if one is available.
3251
Right now, the only way this is available is if 'medusa' is installed.
3252
http://www.amk.ca/python/code/medusa.html
3257
import bzrlib.tests.ftp_server
3262
def feature_name(self):
3265
FTPServerFeature = _FTPServerFeature()
3268
class _UnicodeFilename(Feature):
3269
"""Does the filesystem support Unicode filenames?"""
3274
except UnicodeEncodeError:
3276
except (IOError, OSError):
3277
# The filesystem allows the Unicode filename but the file doesn't
3281
# The filesystem allows the Unicode filename and the file exists,
3285
UnicodeFilename = _UnicodeFilename()
3288
class _UTF8Filesystem(Feature):
3289
"""Is the filesystem UTF-8?"""
3292
if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
3296
UTF8Filesystem = _UTF8Filesystem()
3299
class _CaseInsensitiveFilesystemFeature(Feature):
3300
"""Check if underlying filesystem is case-insensitive
3301
(e.g. on Windows, Cygwin, MacOS)
3305
if TestCaseWithMemoryTransport.TEST_ROOT is None:
3306
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
3307
TestCaseWithMemoryTransport.TEST_ROOT = root
3309
root = TestCaseWithMemoryTransport.TEST_ROOT
3310
tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
3312
name_a = osutils.pathjoin(tdir, 'a')
3313
name_A = osutils.pathjoin(tdir, 'A')
3315
result = osutils.isdir(name_A)
3316
_rmtree_temp_dir(tdir)
3319
def feature_name(self):
3320
return 'case-insensitive filesystem'
3322
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()