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
2113
def build_tree_contents(self, shape):
2085
2114
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
2116
def assertInWorkingTree(self, path, root_path='.', tree=None):
2114
2117
"""Assert whether path or paths are in the WorkingTree"""
2115
2118
if tree is None:
2324
2338
return result_suite
2341
def filter_suite_by_id_list(suite, test_id_list):
2342
"""Create a test suite by filtering another one.
2344
:param suite: The source suite.
2345
:param test_id_list: A list of the test ids to keep as strings.
2346
:returns: the newly created suite
2348
condition = condition_id_in_list(test_id_list)
2349
result_suite = filter_suite_by_condition(suite, condition)
2327
2353
def exclude_tests_by_re(suite, pattern):
2328
2354
"""Create a test suite which excludes some tests from suite.
2471
2495
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
2497
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
2500
return result.wasStrictlySuccessful()
2527
2544
list_only=list_only,
2528
2545
random_seed=random_seed,
2529
2546
exclude_pattern=exclude_pattern,
2531
coverage_dir=coverage_dir)
2533
2549
default_transport = old_transport
2552
def load_test_id_list(file_name):
2553
"""Load a test id list from a text file.
2555
The format is one test id by line. No special care is taken to impose
2556
strict rules, these test ids are used to filter the test suite so a test id
2557
that do not match an existing test will do no harm. This allows user to add
2558
comments, leave blank lines, etc.
2562
ftest = open(file_name, 'rt')
2564
if e.errno != errno.ENOENT:
2567
raise errors.NoSuchFile(file_name)
2569
for test_name in ftest.readlines():
2570
test_list.append(test_name.strip())
2575
class TestIdList(object):
2576
"""Test id list to filter a test suite.
2578
Relying on the assumption that test ids are built as:
2579
<module>[.<class>.<method>][(<param>+)], <module> being in python dotted
2580
notation, this class offers methods to :
2581
- avoid building a test suite for modules not refered to in the test list,
2582
- keep only the tests listed from the module test suite.
2585
def __init__(self, test_id_list):
2586
# When a test suite needs to be filtered against us we compare test ids
2587
# for equality, so a simple dict offers a quick and simple solution.
2588
self.tests = dict().fromkeys(test_id_list, True)
2590
# While unittest.TestCase have ids like:
2591
# <module>.<class>.<method>[(<param+)],
2592
# doctest.DocTestCase can have ids like:
2595
# <module>.<function>
2596
# <module>.<class>.<method>
2598
# Since we can't predict a test class from its name only, we settle on
2599
# a simple constraint: a test id always begins with its module name.
2602
for test_id in test_id_list:
2603
parts = test_id.split('.')
2604
mod_name = parts.pop(0)
2605
modules[mod_name] = True
2607
mod_name += '.' + part
2608
modules[mod_name] = True
2609
self.modules = modules
2611
def is_module_name_used(self, module_name):
2612
"""Is there tests for the module or one of its sub modules."""
2613
return self.modules.has_key(module_name)
2615
def test_in(self, test_id):
2616
return self.tests.has_key(test_id)
2619
def test_suite(keep_only=None):
2537
2620
"""Build and return TestSuite for the whole of bzrlib.
2622
:param keep_only: A list of test ids limiting the suite returned.
2539
2624
This function can be replaced if you need to change the default test
2540
2625
suite on a global basis, but it is not encouraged.
2580
2665
'bzrlib.tests.test_help',
2581
2666
'bzrlib.tests.test_hooks',
2582
2667
'bzrlib.tests.test_http',
2668
'bzrlib.tests.test_http_implementations',
2583
2669
'bzrlib.tests.test_http_response',
2584
2670
'bzrlib.tests.test_https_ca_bundle',
2585
2671
'bzrlib.tests.test_identitymap',
2674
2760
suite = TestUtil.TestSuite()
2675
2761
loader = TestUtil.TestLoader()
2676
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2763
if keep_only is not None:
2764
id_filter = TestIdList(keep_only)
2766
# modules building their suite with loadTestsFromModuleNames
2767
if keep_only is None:
2768
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2770
for mod in [m for m in testmod_names
2771
if id_filter.is_module_name_used(m)]:
2772
mod_suite = loader.loadTestsFromModuleNames([mod])
2773
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2774
suite.addTest(mod_suite)
2776
# modules adapted for transport implementations
2677
2777
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2678
2778
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:
2779
if keep_only is None:
2780
adapt_modules(test_transport_implementations, adapter, loader, suite)
2782
for mod in [m for m in test_transport_implementations
2783
if id_filter.is_module_name_used(m)]:
2784
mod_suite = TestUtil.TestSuite()
2785
adapt_modules([mod], adapter, loader, mod_suite)
2786
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2787
suite.addTest(mod_suite)
2789
# modules defining their own test_suite()
2790
for package in [p for p in packages_to_test()
2791
if (keep_only is None
2792
or id_filter.is_module_name_used(p.__name__))]:
2793
pack_suite = package.test_suite()
2794
if keep_only is not None:
2795
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2796
suite.addTest(pack_suite)
2798
# XXX: MODULES_TO_TEST should be obsoleted ?
2799
for mod in [m for m in MODULES_TO_TEST
2800
if keep_only is None or id_filter.is_module_name_used(m)]:
2801
mod_suite = loader.loadTestsFromModule(mod)
2802
if keep_only is not None:
2803
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2804
suite.addTest(mod_suite)
2806
for mod in MODULES_TO_DOCTEST:
2686
suite.addTest(doctest.DocTestSuite(m))
2808
doc_suite = doctest.DocTestSuite(mod)
2687
2809
except ValueError, e:
2688
print '**failed to get doctest for: %s\n%s' %(m,e)
2810
print '**failed to get doctest for: %s\n%s' % (mod, e)
2812
if keep_only is not None:
2813
# DocTests may use ids which doesn't contain the module name
2814
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2815
suite.addTest(doc_suite)
2690
2817
default_encoding = sys.getdefaultencoding()
2691
for name, plugin in bzrlib.plugin.plugins().items():
2818
for name, plugin in [(n, p) for (n, p) in bzrlib.plugin.plugins().items()
2819
if (keep_only is None
2820
or id_filter.is_module_name_used(
2821
p.module.__name__))]:
2693
2823
plugin_suite = plugin.test_suite()
2694
2824
except ImportError, e: