~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Robert Collins
  • Date: 2008-09-19 06:53:41 UTC
  • mto: (3696.5.1 commit-updates)
  • mto: This revision was merged to the branch mainline in revision 3741.
  • Revision ID: robertc@robertcollins.net-20080919065341-5t5w1p2gi926nfia
First cut - make it work - at updating the tree stat cache during commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    progress,
59
59
    ui,
60
60
    urlutils,
 
61
    registry,
61
62
    workingtree,
62
63
    )
63
64
import bzrlib.branch
2302
2303
    return condition
2303
2304
 
2304
2305
 
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.
2307
2308
    
2308
 
    :param start: A string.
2309
 
    :return: A callable that returns True if the test's id starts with the
2310
 
        given string.
 
2309
    :param starts: A list of string.
 
2310
    :return: A callable that returns True if the test's id starts with one of 
 
2311
        the given strings.
2311
2312
    """
2312
2313
    def condition(test):
2313
 
        return test.id().startswith(start)
 
2314
        for start in starts:
 
2315
            if test.id().startswith(start):
 
2316
                return True
 
2317
        return False
2314
2318
    return condition
2315
2319
 
2316
2320
 
2338
2342
        test case which should be included in the result.
2339
2343
    :return: A suite which contains the tests found in suite that pass
2340
2344
        condition.
2341
 
    """ 
 
2345
    """
2342
2346
    result = []
2343
2347
    for test in iter_suite_tests(suite):
2344
2348
        if condition(test):
2352
2356
    :param suite:           the source suite
2353
2357
    :param pattern:         pattern that names must match
2354
2358
    :returns: the newly created suite
2355
 
    """ 
 
2359
    """
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.
2375
2379
 
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
2379
2383
    """
2380
2384
    condition = condition_id_startswith(start)
2427
2431
        suite matching the condition, and the second contains the remainder
2428
2432
        from suite. The order within each output suite is the same as it was in
2429
2433
        suite.
2430
 
    """ 
 
2434
    """
2431
2435
    matched = []
2432
2436
    did_not_match = []
2433
2437
    for test in iter_suite_tests(suite):
2449
2453
        suite matching pattern, and the second contains the remainder from
2450
2454
        suite. The order within each output suite is the same as it was in
2451
2455
        suite.
2452
 
    """ 
 
2456
    """
2453
2457
    return split_suite_by_condition(suite, condition_id_re(pattern))
2454
2458
 
2455
2459
 
2671
2675
        return self.tests.has_key(test_id)
2672
2676
 
2673
2677
 
 
2678
class TestPrefixAliasRegistry(registry.Registry):
 
2679
    """A registry for test prefix aliases.
 
2680
 
 
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).
 
2684
    """
 
2685
 
 
2686
    def register(self, key, obj, help=None, info=None,
 
2687
                 override_existing=False):
 
2688
        """See Registry.register.
 
2689
 
 
2690
        Trying to override an existing alias causes a warning to be emitted,
 
2691
        not a fatal execption.
 
2692
        """
 
2693
        try:
 
2694
            super(TestPrefixAliasRegistry, self).register(
 
2695
                key, obj, help=help, info=info, override_existing=False)
 
2696
        except KeyError:
 
2697
            actual = self.get(key)
 
2698
            note('Test prefix alias %s is already used for %s, ignoring %s'
 
2699
                 % (key, actual, obj))
 
2700
 
 
2701
    def resolve_alias(self, id_start):
 
2702
        """Replace the alias by the prefix in the given string.
 
2703
 
 
2704
        Using an unknown prefix is an error to help catching typos.
 
2705
        """
 
2706
        parts = id_start.split('.')
 
2707
        try:
 
2708
            parts[0] = self.get(parts[0])
 
2709
        except KeyError:
 
2710
            raise errors.BzrCommandError(
 
2711
                '%s is not a known test prefix alias' % parts[0])
 
2712
        return '.'.join(parts)
 
2713
 
 
2714
 
 
2715
test_prefix_alias_registry = TestPrefixAliasRegistry()
 
2716
"""Registry of test prefix aliases."""
 
2717
 
 
2718
 
 
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')
 
2722
 
 
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')
 
2729
 
 
2730
 
2674
2731
def test_suite(keep_only=None, starting_with=None):
2675
2732
    """Build and return TestSuite for the whole of bzrlib.
2676
2733
 
2693
2750
                   'bzrlib.tests.interrepository_implementations',
2694
2751
                   'bzrlib.tests.intertree_implementations',
2695
2752
                   'bzrlib.tests.per_lock',
2696
 
                   'bzrlib.tests.repository_implementations',
 
2753
                   'bzrlib.tests.per_repository',
2697
2754
                   'bzrlib.tests.test__dirstate_helpers',
2698
2755
                   'bzrlib.tests.test_ancestry',
2699
2756
                   'bzrlib.tests.test_annotate',
2811
2868
                   'bzrlib.tests.test_transform',
2812
2869
                   'bzrlib.tests.test_transport',
2813
2870
                   'bzrlib.tests.test_transport_implementations',
 
2871
                   'bzrlib.tests.test_transport_log',
2814
2872
                   'bzrlib.tests.test_tree',
2815
2873
                   'bzrlib.tests.test_treebuilder',
2816
2874
                   'bzrlib.tests.test_tsort',
2837
2895
 
2838
2896
    loader = TestUtil.TestLoader()
2839
2897
 
2840
 
    if starting_with is not None:
 
2898
    if starting_with:
 
2899
        starting_with = [test_prefix_alias_registry.resolve_alias(start)
 
2900
                         for start in starting_with]
2841
2901
        # We take precedence over keep_only because *at loading time* using
2842
2902
        # both options means we will load less tests for the same final result.
2843
2903
        def interesting_module(name):
2844
 
            return (
2845
 
                # Either the module name starts with the specified string
2846
 
                name.startswith(starting_with)
2847
 
                # or it may contain tests starting with the specified string
2848
 
                or starting_with.startswith(name)
2849
 
                )
 
2904
            for start in starting_with:
 
2905
                if (
 
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)
 
2910
                    ):
 
2911
                    return True
 
2912
            return False
2850
2913
        loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2851
2914
 
2852
2915
    elif keep_only is not None:
2912
2975
            reload(sys)
2913
2976
            sys.setdefaultencoding(default_encoding)
2914
2977
 
2915
 
    if starting_with is not None:
 
2978
    if starting_with:
2916
2979
        suite = filter_suite_by_id_startswith(suite, starting_with)
2917
2980
 
2918
2981
    if keep_only is not None:
2921
2984
        suite = filter_suite_by_id_list(suite, id_filter)
2922
2985
        # Do some sanity checks on the id_list filtering
2923
2986
        not_found, duplicates = suite_matches_id_list(suite, keep_only)
2924
 
        if starting_with is not None:
 
2987
        if starting_with:
2925
2988
            # The tester has used both keep_only and starting_with, so he is
2926
2989
            # already aware that some tests are excluded from the list, there
2927
2990
            # is no need to tell him which.
3234
3297
 
3235
3298
 
3236
3299
class _CaseInsensitiveFilesystemFeature(Feature):
3237
 
    """Check if underlined filesystem is case-insensitive
 
3300
    """Check if underlying filesystem is case-insensitive
3238
3301
    (e.g. on Windows, Cygwin, MacOS)
3239
3302
    """
3240
3303