1040
1041
self.fail('Unexpected success. Should have failed: %s' % reason)
1043
def assertFileEqual(self, content, path):
1044
"""Fail if path does not contain 'content'."""
1045
self.failUnlessExists(path)
1046
f = file(path, 'rb')
1051
self.assertEqualDiff(content, s)
1053
def failUnlessExists(self, path):
1054
"""Fail unless path or paths, which may be abs or relative, exist."""
1055
if not isinstance(path, basestring):
1057
self.failUnlessExists(p)
1059
self.failUnless(osutils.lexists(path),path+" does not exist")
1061
def failIfExists(self, path):
1062
"""Fail if path or paths, which may be abs or relative, exist."""
1063
if not isinstance(path, basestring):
1065
self.failIfExists(p)
1067
self.failIf(osutils.lexists(path),path+" exists")
1042
1069
def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1043
1070
"""A helper for callDeprecated and applyDeprecated.
2084
2114
def build_tree_contents(self, shape):
2085
2115
build_tree_contents(shape)
2087
def assertFileEqual(self, content, path):
2088
"""Fail if path does not contain 'content'."""
2089
self.failUnlessExists(path)
2090
f = file(path, 'rb')
2095
self.assertEqualDiff(content, s)
2097
def failUnlessExists(self, path):
2098
"""Fail unless path or paths, which may be abs or relative, exist."""
2099
if not isinstance(path, basestring):
2101
self.failUnlessExists(p)
2103
self.failUnless(osutils.lexists(path),path+" does not exist")
2105
def failIfExists(self, path):
2106
"""Fail if path or paths, which may be abs or relative, exist."""
2107
if not isinstance(path, basestring):
2109
self.failIfExists(p)
2111
self.failIf(osutils.lexists(path),path+" exists")
2113
2117
def assertInWorkingTree(self, path, root_path='.', tree=None):
2114
2118
"""Assert whether path or paths are in the WorkingTree"""
2115
2119
if tree is None:
2324
2339
return result_suite
2342
def filter_suite_by_id_list(suite, test_id_list):
2343
"""Create a test suite by filtering another one.
2345
:param suite: The source suite.
2346
:param test_id_list: A list of the test ids to keep as strings.
2347
:returns: the newly created suite
2349
condition = condition_id_in_list(test_id_list)
2350
result_suite = filter_suite_by_condition(suite, condition)
2327
2354
def exclude_tests_by_re(suite, pattern):
2328
2355
"""Create a test suite which excludes some tests from suite.
2471
2496
suite = order_changer(filter_suite_by_re(suite, pattern))
2473
# Activate code coverage.
2474
if coverage_dir is not None:
2475
tracer = trace.Trace(count=1, trace=0)
2476
sys.settrace(tracer.globaltrace)
2478
2498
result = runner.run(suite)
2480
if coverage_dir is not None:
2482
results = tracer.results()
2483
results.write_results(show_missing=1, summary=False,
2484
coverdir=coverage_dir)
2487
2501
return result.wasStrictlySuccessful()
2527
2545
list_only=list_only,
2528
2546
random_seed=random_seed,
2529
2547
exclude_pattern=exclude_pattern,
2531
coverage_dir=coverage_dir)
2533
2550
default_transport = old_transport
2553
def load_test_id_list(file_name):
2554
"""Load a test id list from a text file.
2556
The format is one test id by line. No special care is taken to impose
2557
strict rules, these test ids are used to filter the test suite so a test id
2558
that do not match an existing test will do no harm. This allows user to add
2559
comments, leave blank lines, etc.
2563
ftest = open(file_name, 'rt')
2565
if e.errno != errno.ENOENT:
2568
raise errors.NoSuchFile(file_name)
2570
for test_name in ftest.readlines():
2571
test_list.append(test_name.strip())
2576
class TestIdList(object):
2577
"""Test id list to filter a test suite.
2579
Relying on the assumption that test ids are built as:
2580
<module>[.<class>.<method>][(<param>+)], <module> being in python dotted
2581
notation, this class offers methods to :
2582
- avoid building a test suite for modules not refered to in the test list,
2583
- keep only the tests listed from the module test suite.
2586
def __init__(self, test_id_list):
2587
# When a test suite needs to be filtered against us we compare test ids
2588
# for equality, so a simple dict offers a quick and simple solution.
2589
self.tests = dict().fromkeys(test_id_list, True)
2591
# While unittest.TestCase have ids like:
2592
# <module>.<class>.<method>[(<param+)],
2593
# doctest.DocTestCase can have ids like:
2596
# <module>.<function>
2597
# <module>.<class>.<method>
2599
# Since we can't predict a test class from its name only, we settle on
2600
# a simple constraint: a test id always begins with its module name.
2603
for test_id in test_id_list:
2604
parts = test_id.split('.')
2605
mod_name = parts.pop(0)
2606
modules[mod_name] = True
2608
mod_name += '.' + part
2609
modules[mod_name] = True
2610
self.modules = modules
2612
def is_module_name_used(self, module_name):
2613
"""Is there tests for the module or one of its sub modules."""
2614
return self.modules.has_key(module_name)
2616
def test_in(self, test_id):
2617
return self.tests.has_key(test_id)
2620
def test_suite(keep_only=None):
2537
2621
"""Build and return TestSuite for the whole of bzrlib.
2623
:param keep_only: A list of test ids limiting the suite returned.
2539
2625
This function can be replaced if you need to change the default test
2540
2626
suite on a global basis, but it is not encouraged.
2580
2666
'bzrlib.tests.test_help',
2581
2667
'bzrlib.tests.test_hooks',
2582
2668
'bzrlib.tests.test_http',
2669
'bzrlib.tests.test_http_implementations',
2583
2670
'bzrlib.tests.test_http_response',
2584
2671
'bzrlib.tests.test_https_ca_bundle',
2585
2672
'bzrlib.tests.test_identitymap',
2674
2761
suite = TestUtil.TestSuite()
2675
2762
loader = TestUtil.TestLoader()
2676
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2764
if keep_only is not None:
2765
id_filter = TestIdList(keep_only)
2767
# modules building their suite with loadTestsFromModuleNames
2768
if keep_only is None:
2769
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2771
for mod in [m for m in testmod_names
2772
if id_filter.is_module_name_used(m)]:
2773
mod_suite = loader.loadTestsFromModuleNames([mod])
2774
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2775
suite.addTest(mod_suite)
2777
# modules adapted for transport implementations
2677
2778
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2678
2779
adapter = TransportTestProviderAdapter()
2679
adapt_modules(test_transport_implementations, adapter, loader, suite)
2680
for package in packages_to_test():
2681
suite.addTest(package.test_suite())
2682
for m in MODULES_TO_TEST:
2683
suite.addTest(loader.loadTestsFromModule(m))
2684
for m in MODULES_TO_DOCTEST:
2780
if keep_only is None:
2781
adapt_modules(test_transport_implementations, adapter, loader, suite)
2783
for mod in [m for m in test_transport_implementations
2784
if id_filter.is_module_name_used(m)]:
2785
mod_suite = TestUtil.TestSuite()
2786
adapt_modules([mod], adapter, loader, mod_suite)
2787
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2788
suite.addTest(mod_suite)
2790
# modules defining their own test_suite()
2791
for package in [p for p in packages_to_test()
2792
if (keep_only is None
2793
or id_filter.is_module_name_used(p.__name__))]:
2794
pack_suite = package.test_suite()
2795
if keep_only is not None:
2796
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2797
suite.addTest(pack_suite)
2799
# XXX: MODULES_TO_TEST should be obsoleted ?
2800
for mod in [m for m in MODULES_TO_TEST
2801
if keep_only is None or id_filter.is_module_name_used(m)]:
2802
mod_suite = loader.loadTestsFromModule(mod)
2803
if keep_only is not None:
2804
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2805
suite.addTest(mod_suite)
2807
for mod in MODULES_TO_DOCTEST:
2686
suite.addTest(doctest.DocTestSuite(m))
2809
doc_suite = doctest.DocTestSuite(mod)
2687
2810
except ValueError, e:
2688
print '**failed to get doctest for: %s\n%s' %(m,e)
2811
print '**failed to get doctest for: %s\n%s' % (mod, e)
2813
if keep_only is not None:
2814
# DocTests may use ids which doesn't contain the module name
2815
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2816
suite.addTest(doc_suite)
2690
2818
default_encoding = sys.getdefaultencoding()
2691
for name, plugin in bzrlib.plugin.plugins().items():
2819
for name, plugin in [(n, p) for (n, p) in bzrlib.plugin.plugins().items()
2820
if (keep_only is None
2821
or id_filter.is_module_name_used(
2822
p.module.__name__))]:
2693
2824
plugin_suite = plugin.test_suite()
2694
2825
except ImportError, e: