2323
2334
return result_suite
2337
def filter_suite_by_id_list(suite, test_id_list):
2338
"""Create a test suite by filtering another one.
2340
:param suite: The source suite.
2341
:param test_id_list: A list of the test ids to keep as strings.
2342
:returns: the newly created suite
2344
condition = condition_id_in_list(test_id_list)
2345
result_suite = filter_suite_by_condition(suite, condition)
2326
2349
def exclude_tests_by_re(suite, pattern):
2327
2350
"""Create a test suite which excludes some tests from suite.
2517
2545
default_transport = old_transport
2548
def load_test_id_list(file_name):
2549
"""Load a test id list from a text file.
2551
The format is one test id by line. No special care is taken to impose
2552
strict rules, these test ids are used to filter the test suite so a test id
2553
that do not match an existing test will do no harm. This allows user to add
2554
comments, leave blank lines, etc.
2558
ftest = open(file_name, 'rt')
2560
if e.errno != errno.ENOENT:
2563
raise errors.NoSuchFile(file_name)
2565
for test_name in ftest.readlines():
2566
test_list.append(test_name.strip())
2571
class TestIdList(object):
2572
"""Test id list to filter a test suite.
2574
Relying on the assumption that test ids are built as:
2575
<module>[.<class>.<method>][(<param>+)], <module> being in python dotted
2576
notation, this class offers methods to :
2577
- avoid building a test suite for modules not refered to in the test list,
2578
- keep only the tests listed from the module test suite.
2581
def __init__(self, test_id_list):
2582
# When a test suite needs to be filtered against us we compare test ids
2583
# for equality, so a simple dict offers a quick and simple solution.
2584
self.tests = dict().fromkeys(test_id_list, True)
2586
# While unittest.TestCase have ids like:
2587
# <module>.<class>.<method>[(<param+)],
2588
# doctest.DocTestCase can have ids like:
2591
# <module>.<function>
2592
# <module>.<class>.<method>
2594
# Since we can't predict a test class from its name only, we settle on
2595
# a simple constraint: a test id always begins with its module name.
2598
for test_id in test_id_list:
2599
parts = test_id.split('.')
2600
mod_name = parts.pop(0)
2601
modules[mod_name] = True
2603
mod_name += '.' + part
2604
modules[mod_name] = True
2605
self.modules = modules
2607
def is_module_name_used(self, module_name):
2608
"""Is there tests for the module or one of its sub modules."""
2609
return self.modules.has_key(module_name)
2611
def test_in(self, test_id):
2612
return self.tests.has_key(test_id)
2615
def test_suite(keep_only=None):
2521
2616
"""Build and return TestSuite for the whole of bzrlib.
2618
:param keep_only: A list of test ids limiting the suite returned.
2523
2620
This function can be replaced if you need to change the default test
2524
2621
suite on a global basis, but it is not encouraged.
2659
2756
suite = TestUtil.TestSuite()
2660
2757
loader = TestUtil.TestLoader()
2661
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2759
if keep_only is not None:
2760
id_filter = TestIdList(keep_only)
2762
# modules building their suite with loadTestsFromModuleNames
2763
if keep_only is None:
2764
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2766
for mod in [m for m in testmod_names
2767
if id_filter.is_module_name_used(m)]:
2768
mod_suite = loader.loadTestsFromModuleNames([mod])
2769
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2770
suite.addTest(mod_suite)
2772
# modules adapted for transport implementations
2662
2773
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2663
2774
adapter = TransportTestProviderAdapter()
2664
adapt_modules(test_transport_implementations, adapter, loader, suite)
2665
for package in packages_to_test():
2666
suite.addTest(package.test_suite())
2667
for m in MODULES_TO_TEST:
2668
suite.addTest(loader.loadTestsFromModule(m))
2669
for m in MODULES_TO_DOCTEST:
2775
if keep_only is None:
2776
adapt_modules(test_transport_implementations, adapter, loader, suite)
2778
for mod in [m for m in test_transport_implementations
2779
if id_filter.is_module_name_used(m)]:
2780
mod_suite = TestUtil.TestSuite()
2781
adapt_modules([mod], adapter, loader, mod_suite)
2782
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2783
suite.addTest(mod_suite)
2785
# modules defining their own test_suite()
2786
for package in [p for p in packages_to_test()
2787
if (keep_only is None
2788
or id_filter.is_module_name_used(p.__name__))]:
2789
pack_suite = package.test_suite()
2790
if keep_only is not None:
2791
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2792
suite.addTest(pack_suite)
2794
# XXX: MODULES_TO_TEST should be obsoleted ?
2795
for mod in [m for m in MODULES_TO_TEST
2796
if keep_only is None or id_filter.is_module_name_used(m)]:
2797
mod_suite = loader.loadTestsFromModule(mod)
2798
if keep_only is not None:
2799
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2800
suite.addTest(mod_suite)
2802
for mod in MODULES_TO_DOCTEST:
2671
suite.addTest(doctest.DocTestSuite(m))
2804
doc_suite = doctest.DocTestSuite(mod)
2672
2805
except ValueError, e:
2673
print '**failed to get doctest for: %s\n%s' %(m,e)
2806
print '**failed to get doctest for: %s\n%s' % (mod, e)
2808
if keep_only is not None:
2809
# DocTests may use ids which doesn't contain the module name
2810
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2811
suite.addTest(doc_suite)
2675
2813
default_encoding = sys.getdefaultencoding()
2676
for name, plugin in bzrlib.plugin.plugins().items():
2814
for name, plugin in [(n, p) for (n, p) in bzrlib.plugin.plugins().items()
2815
if (keep_only is None
2816
or id_filter.is_module_name_used(
2817
p.module.__name__))]:
2678
2819
plugin_suite = plugin.test_suite()
2679
2820
except ImportError, e: