2302
2303
return condition
2305
def condition_id_startswith(start):
2306
def condition_id_startswith(starts):
2306
2307
"""Create a condition filter verifying that test's id starts with a string.
2308
:param start: A string.
2309
:return: A callable that returns True if the test's id starts with the
2309
:param starts: A list of string.
2310
:return: A callable that returns True if the test's id starts with one of
2312
2313
def condition(test):
2313
return test.id().startswith(start)
2314
for start in starts:
2315
if test.id().startswith(start):
2314
2318
return condition
2352
2356
:param suite: the source suite
2353
2357
:param pattern: pattern that names must match
2354
2358
:returns: the newly created suite
2356
2360
condition = condition_id_re(pattern)
2357
2361
result_suite = filter_suite_by_condition(suite, condition)
2358
2362
return result_suite
2374
2378
"""Create a test suite by filtering another one.
2376
2380
:param suite: The source suite.
2377
:param start: A string the test id must start with.
2381
:param start: A list of string the test id must start with one of.
2378
2382
:returns: the newly created suite
2380
2384
condition = condition_id_startswith(start)
2671
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')
2674
2731
def test_suite(keep_only=None, starting_with=None):
2675
2732
"""Build and return TestSuite for the whole of bzrlib.
2703
2760
'bzrlib.tests.test_bisect_multi',
2704
2761
'bzrlib.tests.test_branch',
2705
2762
'bzrlib.tests.test_branchbuilder',
2763
'bzrlib.tests.test_btree_index',
2706
2764
'bzrlib.tests.test_bugtracker',
2707
2765
'bzrlib.tests.test_bundle',
2708
2766
'bzrlib.tests.test_bzrdir',
2709
2767
'bzrlib.tests.test_cache_utf8',
2768
'bzrlib.tests.test_chunk_writer',
2710
2769
'bzrlib.tests.test_commands',
2711
2770
'bzrlib.tests.test_commit',
2712
2771
'bzrlib.tests.test_commit_merge',
2836
2895
loader = TestUtil.TestLoader()
2838
if starting_with is not None:
2898
starting_with = [test_prefix_alias_registry.resolve_alias(start)
2899
for start in starting_with]
2839
2900
# We take precedence over keep_only because *at loading time* using
2840
2901
# both options means we will load less tests for the same final result.
2841
2902
def interesting_module(name):
2843
# Either the module name starts with the specified string
2844
name.startswith(starting_with)
2845
# or it may contain tests starting with the specified string
2846
or starting_with.startswith(name)
2903
for start in starting_with:
2905
# Either the module name starts with the specified string
2906
name.startswith(start)
2907
# or it may contain tests starting with the specified string
2908
or start.startswith(name)
2848
2912
loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2850
2914
elif keep_only is not None:
2919
2983
suite = filter_suite_by_id_list(suite, id_filter)
2920
2984
# Do some sanity checks on the id_list filtering
2921
2985
not_found, duplicates = suite_matches_id_list(suite, keep_only)
2922
if starting_with is not None:
2923
2987
# The tester has used both keep_only and starting_with, so he is
2924
2988
# already aware that some tests are excluded from the list, there
2925
2989
# is no need to tell him which.