/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-05 03:11:40 UTC
  • mfrom: (3691 +trunk)
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080905031140-hj0adlcf30l7i99v
Merge in bzr.dev 3691

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
1196
1197
        """Make the logfile not be deleted when _finishLogFile is called."""
1197
1198
        self._keep_log_file = True
1198
1199
 
1199
 
    def addCleanup(self, callable):
 
1200
    def addCleanup(self, callable, *args, **kwargs):
1200
1201
        """Arrange to run a callable when this case is torn down.
1201
1202
 
1202
1203
        Callables are run in the reverse of the order they are registered, 
1203
1204
        ie last-in first-out.
1204
1205
        """
1205
 
        if callable in self._cleanups:
1206
 
            raise ValueError("cleanup function %r already registered on %s" 
1207
 
                    % (callable, self))
1208
 
        self._cleanups.append(callable)
 
1206
        self._cleanups.append((callable, args, kwargs))
1209
1207
 
1210
1208
    def _cleanEnvironment(self):
1211
1209
        new_env = {
1320
1318
        # Actually pop the cleanups from the list so tearDown running
1321
1319
        # twice is safe (this happens for skipped tests).
1322
1320
        while self._cleanups:
1323
 
            self._cleanups.pop()()
 
1321
            cleanup, args, kwargs = self._cleanups.pop()
 
1322
            cleanup(*args, **kwargs)
1324
1323
 
1325
1324
    def log(self, *args):
1326
1325
        mutter(*args)
1591
1590
            # so we will avoid using it on all platforms, just to
1592
1591
            # make sure the code path is used, and we don't break on win32
1593
1592
            cleanup_environment()
1594
 
            command = [sys.executable, bzr_path]
 
1593
            command = [sys.executable]
 
1594
            # frozen executables don't need the path to bzr
 
1595
            if getattr(sys, "frozen", None) is None:
 
1596
                command.append(bzr_path)
1595
1597
            if not allow_plugins:
1596
1598
                command.append('--no-plugins')
1597
1599
            command.extend(process_args)
2063
2065
        For TestCaseInTempDir we create a temporary directory based on the test
2064
2066
        name and then create two subdirs - test and home under it.
2065
2067
        """
2066
 
        name_prefix = os.path.join(self.TEST_ROOT, self._getTestDirPrefix())
 
2068
        name_prefix = osutils.pathjoin(self.TEST_ROOT, self._getTestDirPrefix())
2067
2069
        name = name_prefix
2068
2070
        for i in range(100):
2069
2071
            if os.path.exists(name):
2138
2140
            tree = workingtree.WorkingTree.open(root_path)
2139
2141
        if not isinstance(path, basestring):
2140
2142
            for p in path:
2141
 
                self.assertInWorkingTree(p,tree=tree)
 
2143
                self.assertInWorkingTree(p, tree=tree)
2142
2144
        else:
2143
2145
            self.assertIsNot(tree.path2id(path), None,
2144
2146
                path+' not in working tree.')
2301
2303
    return condition
2302
2304
 
2303
2305
 
2304
 
def condition_id_startswith(start):
 
2306
def condition_id_startswith(starts):
2305
2307
    """Create a condition filter verifying that test's id starts with a string.
2306
2308
    
2307
 
    :param start: A string.
2308
 
    :return: A callable that returns True if the test's id starts with the
2309
 
        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.
2310
2312
    """
2311
2313
    def condition(test):
2312
 
        return test.id().startswith(start)
 
2314
        for start in starts:
 
2315
            if test.id().startswith(start):
 
2316
                return True
 
2317
        return False
2313
2318
    return condition
2314
2319
 
2315
2320
 
2337
2342
        test case which should be included in the result.
2338
2343
    :return: A suite which contains the tests found in suite that pass
2339
2344
        condition.
2340
 
    """ 
 
2345
    """
2341
2346
    result = []
2342
2347
    for test in iter_suite_tests(suite):
2343
2348
        if condition(test):
2351
2356
    :param suite:           the source suite
2352
2357
    :param pattern:         pattern that names must match
2353
2358
    :returns: the newly created suite
2354
 
    """ 
 
2359
    """
2355
2360
    condition = condition_id_re(pattern)
2356
2361
    result_suite = filter_suite_by_condition(suite, condition)
2357
2362
    return result_suite
2373
2378
    """Create a test suite by filtering another one.
2374
2379
 
2375
2380
    :param suite: The source suite.
2376
 
    :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.
2377
2382
    :returns: the newly created suite
2378
2383
    """
2379
2384
    condition = condition_id_startswith(start)
2426
2431
        suite matching the condition, and the second contains the remainder
2427
2432
        from suite. The order within each output suite is the same as it was in
2428
2433
        suite.
2429
 
    """ 
 
2434
    """
2430
2435
    matched = []
2431
2436
    did_not_match = []
2432
2437
    for test in iter_suite_tests(suite):
2448
2453
        suite matching pattern, and the second contains the remainder from
2449
2454
        suite. The order within each output suite is the same as it was in
2450
2455
        suite.
2451
 
    """ 
 
2456
    """
2452
2457
    return split_suite_by_condition(suite, condition_id_re(pattern))
2453
2458
 
2454
2459
 
2670
2675
        return self.tests.has_key(test_id)
2671
2676
 
2672
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
 
2673
2731
def test_suite(keep_only=None, starting_with=None):
2674
2732
    """Build and return TestSuite for the whole of bzrlib.
2675
2733
 
2702
2760
                   'bzrlib.tests.test_bisect_multi',
2703
2761
                   'bzrlib.tests.test_branch',
2704
2762
                   'bzrlib.tests.test_branchbuilder',
 
2763
                   'bzrlib.tests.test_btree_index',
2705
2764
                   'bzrlib.tests.test_bugtracker',
2706
2765
                   'bzrlib.tests.test_bundle',
2707
2766
                   'bzrlib.tests.test_bzrdir',
2708
2767
                   'bzrlib.tests.test_cache_utf8',
 
2768
                   'bzrlib.tests.test_chunk_writer',
2709
2769
                   'bzrlib.tests.test_commands',
2710
2770
                   'bzrlib.tests.test_commit',
2711
2771
                   'bzrlib.tests.test_commit_merge',
2763
2823
                   'bzrlib.tests.test_osutils',
2764
2824
                   'bzrlib.tests.test_osutils_encodings',
2765
2825
                   'bzrlib.tests.test_pack',
 
2826
                   'bzrlib.tests.test_pack_repository',
2766
2827
                   'bzrlib.tests.test_patch',
2767
2828
                   'bzrlib.tests.test_patches',
2768
2829
                   'bzrlib.tests.test_permissions',
2807
2868
                   'bzrlib.tests.test_transform',
2808
2869
                   'bzrlib.tests.test_transport',
2809
2870
                   'bzrlib.tests.test_transport_implementations',
 
2871
                   'bzrlib.tests.test_transport_log',
2810
2872
                   'bzrlib.tests.test_tree',
2811
2873
                   'bzrlib.tests.test_treebuilder',
2812
2874
                   'bzrlib.tests.test_tsort',
2814
2876
                   'bzrlib.tests.test_ui',
2815
2877
                   'bzrlib.tests.test_uncommit',
2816
2878
                   'bzrlib.tests.test_upgrade',
 
2879
                   'bzrlib.tests.test_upgrade_stacked',
2817
2880
                   'bzrlib.tests.test_urlutils',
2818
2881
                   'bzrlib.tests.test_versionedfile',
2819
2882
                   'bzrlib.tests.test_version',
2832
2895
 
2833
2896
    loader = TestUtil.TestLoader()
2834
2897
 
2835
 
    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]
2836
2901
        # We take precedence over keep_only because *at loading time* using
2837
2902
        # both options means we will load less tests for the same final result.
2838
2903
        def interesting_module(name):
2839
 
            return (
2840
 
                # Either the module name starts with the specified string
2841
 
                name.startswith(starting_with)
2842
 
                # or it may contain tests starting with the specified string
2843
 
                or starting_with.startswith(name)
2844
 
                )
 
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
2845
2913
        loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2846
2914
 
2847
2915
    elif keep_only is not None:
2907
2975
            reload(sys)
2908
2976
            sys.setdefaultencoding(default_encoding)
2909
2977
 
2910
 
    if starting_with is not None:
 
2978
    if starting_with:
2911
2979
        suite = filter_suite_by_id_startswith(suite, starting_with)
2912
2980
 
2913
2981
    if keep_only is not None:
2916
2984
        suite = filter_suite_by_id_list(suite, id_filter)
2917
2985
        # Do some sanity checks on the id_list filtering
2918
2986
        not_found, duplicates = suite_matches_id_list(suite, keep_only)
2919
 
        if starting_with is not None:
 
2987
        if starting_with:
2920
2988
            # The tester has used both keep_only and starting_with, so he is
2921
2989
            # already aware that some tests are excluded from the list, there
2922
2990
            # is no need to tell him which.
3229
3297
 
3230
3298
 
3231
3299
class _CaseInsensitiveFilesystemFeature(Feature):
3232
 
    """Check if underlined filesystem is case-insensitive
 
3300
    """Check if underlying filesystem is case-insensitive
3233
3301
    (e.g. on Windows, Cygwin, MacOS)
3234
3302
    """
3235
3303