~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-05 04:05:05 UTC
  • mfrom: (3473.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080605040505-i9kqxg2fps2qjdi0
Add the 'alias' command (Tim Penhey)

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
 
51
51
from bzrlib import (
52
 
    branchbuilder,
53
52
    bzrdir,
54
53
    debug,
55
54
    errors,
58
57
    progress,
59
58
    ui,
60
59
    urlutils,
61
 
    registry,
62
60
    workingtree,
63
61
    )
64
62
import bzrlib.branch
220
218
        elif isinstance(err[1], UnavailableFeature):
221
219
            return self.addNotSupported(test, err[1].args[0])
222
220
        else:
 
221
            self._cleanupLogFile(test)
223
222
            unittest.TestResult.addError(self, test, err)
224
223
            self.error_count += 1
225
224
            self.report_error(test, err)
226
225
            if self.stop_early:
227
226
                self.stop()
228
 
            self._cleanupLogFile(test)
229
227
 
230
228
    def addFailure(self, test, err):
231
229
        """Tell result that test failed.
237
235
        if isinstance(err[1], KnownFailure):
238
236
            return self._addKnownFailure(test, err)
239
237
        else:
 
238
            self._cleanupLogFile(test)
240
239
            unittest.TestResult.addFailure(self, test, err)
241
240
            self.failure_count += 1
242
241
            self.report_failure(test, err)
243
242
            if self.stop_early:
244
243
                self.stop()
245
 
            self._cleanupLogFile(test)
246
244
 
247
245
    def addSuccess(self, test):
248
246
        """Tell result that test completed successfully.
793
791
        Tests that want to use debug flags can just set them in the
794
792
        debug_flags set during setup/teardown.
795
793
        """
796
 
        self._preserved_debug_flags = set(debug.debug_flags)
797
794
        if 'allow_debug' not in selftest_debug_flags:
 
795
            self._preserved_debug_flags = set(debug.debug_flags)
798
796
            debug.debug_flags.clear()
799
 
        self.addCleanup(self._restore_debug_flags)
 
797
            self.addCleanup(self._restore_debug_flags)
800
798
 
801
799
    def _clear_hooks(self):
802
800
        # prevent hooks affecting tests
803
801
        import bzrlib.branch
804
 
        import bzrlib.smart.client
805
802
        import bzrlib.smart.server
806
803
        self._preserved_hooks = {
807
804
            bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
808
805
            bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
809
 
            bzrlib.smart.client._SmartClient: bzrlib.smart.client._SmartClient.hooks,
810
806
            bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
811
807
            }
812
808
        self.addCleanup(self._restoreHooks)
813
809
        # reset all hooks to an empty instance of the appropriate type
814
810
        bzrlib.branch.Branch.hooks = bzrlib.branch.BranchHooks()
815
 
        bzrlib.smart.client._SmartClient.hooks = bzrlib.smart.client.SmartClientHooks()
816
811
        bzrlib.smart.server.SmartTCPServer.hooks = bzrlib.smart.server.SmartServerHooks()
817
812
 
818
813
    def _silenceUI(self):
866
861
            return
867
862
        if message is None:
868
863
            message = "texts not equal:\n"
869
 
        if a == b + '\n':
870
 
            message = 'first string is missing a final newline.\n'
871
 
        if a + '\n' == b:
872
 
            message = 'second string is missing a final newline.\n'
873
864
        raise AssertionError(message +
874
865
                             self._ndiff_strings(a, b))
875
866
        
877
868
        self.assertEqual(mode, mode_test,
878
869
                         'mode mismatch %o != %o' % (mode, mode_test))
879
870
 
880
 
    def assertEqualStat(self, expected, actual):
881
 
        """assert that expected and actual are the same stat result.
882
 
 
883
 
        :param expected: A stat result.
884
 
        :param actual: A stat result.
885
 
        :raises AssertionError: If the expected and actual stat values differ
886
 
            other than by atime.
887
 
        """
888
 
        self.assertEqual(expected.st_size, actual.st_size)
889
 
        self.assertEqual(expected.st_mtime, actual.st_mtime)
890
 
        self.assertEqual(expected.st_ctime, actual.st_ctime)
891
 
        self.assertEqual(expected.st_dev, actual.st_dev)
892
 
        self.assertEqual(expected.st_ino, actual.st_ino)
893
 
        self.assertEqual(expected.st_mode, actual.st_mode)
894
 
 
895
871
    def assertPositive(self, val):
896
872
        """Assert that val is greater than 0."""
897
873
        self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)
943
919
        """
944
920
        try:
945
921
            list(func(*args, **kwargs))
946
 
        except excClass, e:
947
 
            return e
 
922
        except excClass:
 
923
            return
948
924
        else:
949
925
            if getattr(excClass,'__name__', None) is not None:
950
926
                excName = excClass.__name__
1149
1125
        # warnings.  It's the easiest way to insulate ourselves from -Werror,
1150
1126
        # though.  -- Andrew, 20071062
1151
1127
        wlist = []
1152
 
        def _catcher(message, category, filename, lineno, file=None, line=None):
 
1128
        def _catcher(message, category, filename, lineno, file=None):
1153
1129
            # despite the name, 'message' is normally(?) a Warning subclass
1154
1130
            # instance
1155
1131
            wlist.append(message)
1215
1191
        """Make the logfile not be deleted when _finishLogFile is called."""
1216
1192
        self._keep_log_file = True
1217
1193
 
1218
 
    def addCleanup(self, callable, *args, **kwargs):
 
1194
    def addCleanup(self, callable):
1219
1195
        """Arrange to run a callable when this case is torn down.
1220
1196
 
1221
1197
        Callables are run in the reverse of the order they are registered, 
1222
1198
        ie last-in first-out.
1223
1199
        """
1224
 
        self._cleanups.append((callable, args, kwargs))
 
1200
        if callable in self._cleanups:
 
1201
            raise ValueError("cleanup function %r already registered on %s" 
 
1202
                    % (callable, self))
 
1203
        self._cleanups.append(callable)
1225
1204
 
1226
1205
    def _cleanEnvironment(self):
1227
1206
        new_env = {
1228
1207
            'BZR_HOME': None, # Don't inherit BZR_HOME to all the tests.
1229
1208
            'HOME': os.getcwd(),
1230
 
            # bzr now uses the Win32 API and doesn't rely on APPDATA, but the
1231
 
            # tests do check our impls match APPDATA
 
1209
            'APPDATA': None,  # bzr now use Win32 API and don't rely on APPDATA
1232
1210
            'BZR_EDITOR': None, # test_msgeditor manipulates this variable
1233
1211
            'BZR_EMAIL': None,
1234
1212
            'BZREMAIL': None, # may still be present in the environment
1337
1315
        # Actually pop the cleanups from the list so tearDown running
1338
1316
        # twice is safe (this happens for skipped tests).
1339
1317
        while self._cleanups:
1340
 
            cleanup, args, kwargs = self._cleanups.pop()
1341
 
            cleanup(*args, **kwargs)
 
1318
            self._cleanups.pop()()
1342
1319
 
1343
1320
    def log(self, *args):
1344
1321
        mutter(*args)
1354
1331
        """
1355
1332
        # flush the log file, to get all content
1356
1333
        import bzrlib.trace
1357
 
        if bzrlib.trace._trace_file:
1358
 
            bzrlib.trace._trace_file.flush()
 
1334
        bzrlib.trace._trace_file.flush()
1359
1335
        if self._log_contents:
1360
1336
            # XXX: this can hardly contain the content flushed above --vila
1361
1337
            # 20080128
1402
1378
    def _run_bzr_core(self, args, retcode, encoding, stdin,
1403
1379
            working_dir):
1404
1380
        if encoding is None:
1405
 
            encoding = osutils.get_user_encoding()
 
1381
            encoding = bzrlib.user_encoding
1406
1382
        stdout = StringIOWrapper()
1407
1383
        stderr = StringIOWrapper()
1408
1384
        stdout.encoding = encoding
1610
1586
            # so we will avoid using it on all platforms, just to
1611
1587
            # make sure the code path is used, and we don't break on win32
1612
1588
            cleanup_environment()
1613
 
            command = [sys.executable]
1614
 
            # frozen executables don't need the path to bzr
1615
 
            if getattr(sys, "frozen", None) is None:
1616
 
                command.append(bzr_path)
 
1589
            command = [sys.executable, bzr_path]
1617
1590
            if not allow_plugins:
1618
1591
                command.append('--no-plugins')
1619
1592
            command.extend(process_args)
2016
1989
        b = self.make_branch(relpath, format=format)
2017
1990
        return memorytree.MemoryTree.create_on_branch(b)
2018
1991
 
2019
 
    def make_branch_builder(self, relpath, format=None):
2020
 
        url = self.get_url(relpath)
2021
 
        tran = get_transport(url)
2022
 
        return branchbuilder.BranchBuilder(get_transport(url), format=format)
2023
 
 
2024
1992
    def overrideEnvironmentForTesting(self):
2025
1993
        os.environ['HOME'] = self.test_home_dir
2026
1994
        os.environ['BZR_HOME'] = self.test_home_dir
2069
2037
            self.log("actually: %r" % contents)
2070
2038
            self.fail("contents of %s not as expected" % filename)
2071
2039
 
2072
 
    def _getTestDirPrefix(self):
2073
 
        # create a directory within the top level test directory
2074
 
        if sys.platform == 'win32':
2075
 
            name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2076
 
            # windows is likely to have path-length limits so use a short name
2077
 
            name_prefix = name_prefix[-30:]
2078
 
        else:
2079
 
            name_prefix = re.sub('[/]', '_', self.id())
2080
 
        return name_prefix
2081
 
 
2082
2040
    def makeAndChdirToTestDir(self):
2083
2041
        """See TestCaseWithMemoryTransport.makeAndChdirToTestDir().
2084
2042
        
2085
2043
        For TestCaseInTempDir we create a temporary directory based on the test
2086
2044
        name and then create two subdirs - test and home under it.
2087
2045
        """
2088
 
        name_prefix = osutils.pathjoin(self.TEST_ROOT, self._getTestDirPrefix())
2089
 
        name = name_prefix
2090
 
        for i in range(100):
2091
 
            if os.path.exists(name):
2092
 
                name = name_prefix + '_' + str(i)
2093
 
            else:
2094
 
                os.mkdir(name)
2095
 
                break
 
2046
        # create a directory within the top level test directory
 
2047
        candidate_dir = osutils.mkdtemp(dir=self.TEST_ROOT)
2096
2048
        # now create test and home directories within this dir
2097
 
        self.test_base_dir = name
 
2049
        self.test_base_dir = candidate_dir
2098
2050
        self.test_home_dir = self.test_base_dir + '/home'
2099
2051
        os.mkdir(self.test_home_dir)
2100
2052
        self.test_dir = self.test_base_dir + '/work'
2160
2112
            tree = workingtree.WorkingTree.open(root_path)
2161
2113
        if not isinstance(path, basestring):
2162
2114
            for p in path:
2163
 
                self.assertInWorkingTree(p, tree=tree)
 
2115
                self.assertInWorkingTree(p,tree=tree)
2164
2116
        else:
2165
2117
            self.assertIsNot(tree.path2id(path), None,
2166
2118
                path+' not in working tree.')
2230
2182
                # the branch is colocated on disk, we cannot create a checkout.
2231
2183
                # hopefully callers will expect this.
2232
2184
                local_controldir= bzrdir.BzrDir.open(self.get_vfs_only_url(relpath))
2233
 
                wt = local_controldir.create_workingtree()
2234
 
                if wt.branch._format != b._format:
2235
 
                    wt._branch = b
2236
 
                    # Make sure that assigning to wt._branch fixes wt.branch,
2237
 
                    # in case the implementation details of workingtree objects
2238
 
                    # change.
2239
 
                    self.assertIs(b, wt.branch)
2240
 
                return wt
 
2185
                return local_controldir.create_workingtree()
2241
2186
            else:
2242
2187
                return b.create_checkout(relpath, lightweight=True)
2243
2188
 
2323
2268
    return condition
2324
2269
 
2325
2270
 
2326
 
def condition_id_startswith(starts):
 
2271
def condition_id_startswith(start):
2327
2272
    """Create a condition filter verifying that test's id starts with a string.
2328
2273
    
2329
 
    :param starts: A list of string.
2330
 
    :return: A callable that returns True if the test's id starts with one of 
2331
 
        the given strings.
 
2274
    :param start: A string.
 
2275
    :return: A callable that returns True if the test's id starts with the
 
2276
        given string.
2332
2277
    """
2333
2278
    def condition(test):
2334
 
        for start in starts:
2335
 
            if test.id().startswith(start):
2336
 
                return True
2337
 
        return False
 
2279
        return test.id().startswith(start)
2338
2280
    return condition
2339
2281
 
2340
2282
 
2362
2304
        test case which should be included in the result.
2363
2305
    :return: A suite which contains the tests found in suite that pass
2364
2306
        condition.
2365
 
    """
 
2307
    """ 
2366
2308
    result = []
2367
2309
    for test in iter_suite_tests(suite):
2368
2310
        if condition(test):
2376
2318
    :param suite:           the source suite
2377
2319
    :param pattern:         pattern that names must match
2378
2320
    :returns: the newly created suite
2379
 
    """
 
2321
    """ 
2380
2322
    condition = condition_id_re(pattern)
2381
2323
    result_suite = filter_suite_by_condition(suite, condition)
2382
2324
    return result_suite
2398
2340
    """Create a test suite by filtering another one.
2399
2341
 
2400
2342
    :param suite: The source suite.
2401
 
    :param start: A list of string the test id must start with one of.
 
2343
    :param start: A string the test id must start with.
2402
2344
    :returns: the newly created suite
2403
2345
    """
2404
2346
    condition = condition_id_startswith(start)
2451
2393
        suite matching the condition, and the second contains the remainder
2452
2394
        from suite. The order within each output suite is the same as it was in
2453
2395
        suite.
2454
 
    """
 
2396
    """ 
2455
2397
    matched = []
2456
2398
    did_not_match = []
2457
2399
    for test in iter_suite_tests(suite):
2473
2415
        suite matching pattern, and the second contains the remainder from
2474
2416
        suite. The order within each output suite is the same as it was in
2475
2417
        suite.
2476
 
    """
 
2418
    """ 
2477
2419
    return split_suite_by_condition(suite, condition_id_re(pattern))
2478
2420
 
2479
2421
 
2695
2637
        return self.tests.has_key(test_id)
2696
2638
 
2697
2639
 
2698
 
class TestPrefixAliasRegistry(registry.Registry):
2699
 
    """A registry for test prefix aliases.
2700
 
 
2701
 
    This helps implement shorcuts for the --starting-with selftest
2702
 
    option. Overriding existing prefixes is not allowed but not fatal (a
2703
 
    warning will be emitted).
2704
 
    """
2705
 
 
2706
 
    def register(self, key, obj, help=None, info=None,
2707
 
                 override_existing=False):
2708
 
        """See Registry.register.
2709
 
 
2710
 
        Trying to override an existing alias causes a warning to be emitted,
2711
 
        not a fatal execption.
2712
 
        """
2713
 
        try:
2714
 
            super(TestPrefixAliasRegistry, self).register(
2715
 
                key, obj, help=help, info=info, override_existing=False)
2716
 
        except KeyError:
2717
 
            actual = self.get(key)
2718
 
            note('Test prefix alias %s is already used for %s, ignoring %s'
2719
 
                 % (key, actual, obj))
2720
 
 
2721
 
    def resolve_alias(self, id_start):
2722
 
        """Replace the alias by the prefix in the given string.
2723
 
 
2724
 
        Using an unknown prefix is an error to help catching typos.
2725
 
        """
2726
 
        parts = id_start.split('.')
2727
 
        try:
2728
 
            parts[0] = self.get(parts[0])
2729
 
        except KeyError:
2730
 
            raise errors.BzrCommandError(
2731
 
                '%s is not a known test prefix alias' % parts[0])
2732
 
        return '.'.join(parts)
2733
 
 
2734
 
 
2735
 
test_prefix_alias_registry = TestPrefixAliasRegistry()
2736
 
"""Registry of test prefix aliases."""
2737
 
 
2738
 
 
2739
 
# This alias allows to detect typos ('bzrlin.') by making all valid test ids
2740
 
# appear prefixed ('bzrlib.' is "replaced" by 'bzrlib.').
2741
 
test_prefix_alias_registry.register('bzrlib', 'bzrlib')
2742
 
 
2743
 
# Obvious higest levels prefixes, feel free to add your own via a plugin
2744
 
test_prefix_alias_registry.register('bd', 'bzrlib.doc')
2745
 
test_prefix_alias_registry.register('bu', 'bzrlib.utils')
2746
 
test_prefix_alias_registry.register('bt', 'bzrlib.tests')
2747
 
test_prefix_alias_registry.register('bb', 'bzrlib.tests.blackbox')
2748
 
test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
2749
 
 
2750
 
 
2751
2640
def test_suite(keep_only=None, starting_with=None):
2752
2641
    """Build and return TestSuite for the whole of bzrlib.
2753
2642
 
2761
2650
    """
2762
2651
    testmod_names = [
2763
2652
                   'bzrlib.doc',
 
2653
                   'bzrlib.util.tests.test_bencode',
2764
2654
                   'bzrlib.tests.blackbox',
2765
2655
                   'bzrlib.tests.branch_implementations',
2766
2656
                   'bzrlib.tests.bzrdir_implementations',
2767
2657
                   'bzrlib.tests.commands',
 
2658
                   'bzrlib.tests.inventory_implementations',
2768
2659
                   'bzrlib.tests.interrepository_implementations',
2769
2660
                   'bzrlib.tests.intertree_implementations',
2770
 
                   'bzrlib.tests.inventory_implementations',
 
2661
                   'bzrlib.tests.interversionedfile_implementations',
2771
2662
                   'bzrlib.tests.per_lock',
2772
 
                   'bzrlib.tests.per_repository',
2773
 
                   'bzrlib.tests.per_repository_reference',
 
2663
                   'bzrlib.tests.repository_implementations',
 
2664
                   'bzrlib.tests.revisionstore_implementations',
2774
2665
                   'bzrlib.tests.test__dirstate_helpers',
2775
 
                   'bzrlib.tests.test__walkdirs_win32',
2776
2666
                   'bzrlib.tests.test_ancestry',
2777
2667
                   'bzrlib.tests.test_annotate',
2778
2668
                   'bzrlib.tests.test_api',
2781
2671
                   'bzrlib.tests.test_bisect_multi',
2782
2672
                   'bzrlib.tests.test_branch',
2783
2673
                   'bzrlib.tests.test_branchbuilder',
2784
 
                   'bzrlib.tests.test_btree_index',
2785
2674
                   'bzrlib.tests.test_bugtracker',
2786
2675
                   'bzrlib.tests.test_bundle',
2787
2676
                   'bzrlib.tests.test_bzrdir',
2788
2677
                   'bzrlib.tests.test_cache_utf8',
2789
 
                   'bzrlib.tests.test_chunk_writer',
2790
2678
                   'bzrlib.tests.test_commands',
2791
2679
                   'bzrlib.tests.test_commit',
2792
2680
                   'bzrlib.tests.test_commit_merge',
2797
2685
                   'bzrlib.tests.test_delta',
2798
2686
                   'bzrlib.tests.test_deprecated_graph',
2799
2687
                   'bzrlib.tests.test_diff',
 
2688
                   'bzrlib.tests.test_dirstate',
2800
2689
                   'bzrlib.tests.test_directory_service',
2801
 
                   'bzrlib.tests.test_dirstate',
2802
2690
                   'bzrlib.tests.test_email_message',
2803
2691
                   'bzrlib.tests.test_errors',
 
2692
                   'bzrlib.tests.test_escaped_store',
2804
2693
                   'bzrlib.tests.test_extract',
2805
2694
                   'bzrlib.tests.test_fetch',
2806
2695
                   'bzrlib.tests.test_ftp_transport',
2824
2713
                   'bzrlib.tests.test_knit',
2825
2714
                   'bzrlib.tests.test_lazy_import',
2826
2715
                   'bzrlib.tests.test_lazy_regex',
 
2716
                   'bzrlib.tests.test_lockdir',
2827
2717
                   'bzrlib.tests.test_lockable_files',
2828
 
                   'bzrlib.tests.test_lockdir',
2829
2718
                   'bzrlib.tests.test_log',
 
2719
                   'bzrlib.tests.test_lsprof',
2830
2720
                   'bzrlib.tests.test_lru_cache',
2831
 
                   'bzrlib.tests.test_lsprof',
2832
2721
                   'bzrlib.tests.test_mail_client',
2833
2722
                   'bzrlib.tests.test_memorytree',
2834
2723
                   'bzrlib.tests.test_merge',
2844
2733
                   'bzrlib.tests.test_osutils',
2845
2734
                   'bzrlib.tests.test_osutils_encodings',
2846
2735
                   'bzrlib.tests.test_pack',
2847
 
                   'bzrlib.tests.test_pack_repository',
2848
2736
                   'bzrlib.tests.test_patch',
2849
2737
                   'bzrlib.tests.test_patches',
2850
2738
                   'bzrlib.tests.test_permissions',
2851
2739
                   'bzrlib.tests.test_plugins',
2852
2740
                   'bzrlib.tests.test_progress',
2853
2741
                   'bzrlib.tests.test_read_bundle',
 
2742
                   'bzrlib.tests.test_reconfigure',
2854
2743
                   'bzrlib.tests.test_reconcile',
2855
 
                   'bzrlib.tests.test_reconfigure',
2856
2744
                   'bzrlib.tests.test_registry',
2857
2745
                   'bzrlib.tests.test_remote',
2858
2746
                   'bzrlib.tests.test_repository',
2861
2749
                   'bzrlib.tests.test_revisionspec',
2862
2750
                   'bzrlib.tests.test_revisiontree',
2863
2751
                   'bzrlib.tests.test_rio',
2864
 
                   'bzrlib.tests.test_rules',
2865
2752
                   'bzrlib.tests.test_sampler',
2866
2753
                   'bzrlib.tests.test_selftest',
2867
2754
                   'bzrlib.tests.test_setup',
2888
2775
                   'bzrlib.tests.test_transform',
2889
2776
                   'bzrlib.tests.test_transport',
2890
2777
                   'bzrlib.tests.test_transport_implementations',
2891
 
                   'bzrlib.tests.test_transport_log',
2892
2778
                   'bzrlib.tests.test_tree',
2893
2779
                   'bzrlib.tests.test_treebuilder',
2894
2780
                   'bzrlib.tests.test_tsort',
2896
2782
                   'bzrlib.tests.test_ui',
2897
2783
                   'bzrlib.tests.test_uncommit',
2898
2784
                   'bzrlib.tests.test_upgrade',
2899
 
                   'bzrlib.tests.test_upgrade_stacked',
2900
2785
                   'bzrlib.tests.test_urlutils',
 
2786
                   'bzrlib.tests.test_versionedfile',
2901
2787
                   'bzrlib.tests.test_version',
2902
2788
                   'bzrlib.tests.test_version_info',
2903
 
                   'bzrlib.tests.test_versionedfile',
2904
2789
                   'bzrlib.tests.test_weave',
2905
2790
                   'bzrlib.tests.test_whitebox',
2906
2791
                   'bzrlib.tests.test_win32utils',
2910
2795
                   'bzrlib.tests.test_xml',
2911
2796
                   'bzrlib.tests.tree_implementations',
2912
2797
                   'bzrlib.tests.workingtree_implementations',
2913
 
                   'bzrlib.util.tests.test_bencode',
2914
2798
                   ]
2915
2799
 
2916
2800
    loader = TestUtil.TestLoader()
2917
2801
 
2918
 
    if starting_with:
2919
 
        starting_with = [test_prefix_alias_registry.resolve_alias(start)
2920
 
                         for start in starting_with]
 
2802
    if starting_with is not None:
2921
2803
        # We take precedence over keep_only because *at loading time* using
2922
2804
        # both options means we will load less tests for the same final result.
2923
2805
        def interesting_module(name):
2924
 
            for start in starting_with:
2925
 
                if (
2926
 
                    # Either the module name starts with the specified string
2927
 
                    name.startswith(start)
2928
 
                    # or it may contain tests starting with the specified string
2929
 
                    or start.startswith(name)
2930
 
                    ):
2931
 
                    return True
2932
 
            return False
 
2806
            return (
 
2807
                # Either the module name starts with the specified string
 
2808
                name.startswith(starting_with)
 
2809
                # or it may contain tests starting with the specified string
 
2810
                or starting_with.startswith(name)
 
2811
                )
2933
2812
        loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2934
2813
 
2935
2814
    elif keep_only is not None:
2995
2874
            reload(sys)
2996
2875
            sys.setdefaultencoding(default_encoding)
2997
2876
 
2998
 
    if starting_with:
 
2877
    if starting_with is not None:
2999
2878
        suite = filter_suite_by_id_startswith(suite, starting_with)
3000
2879
 
3001
2880
    if keep_only is not None:
3004
2883
        suite = filter_suite_by_id_list(suite, id_filter)
3005
2884
        # Do some sanity checks on the id_list filtering
3006
2885
        not_found, duplicates = suite_matches_id_list(suite, keep_only)
3007
 
        if starting_with:
 
2886
        if starting_with is not None:
3008
2887
            # The tester has used both keep_only and starting_with, so he is
3009
2888
            # already aware that some tests are excluded from the list, there
3010
2889
            # is no need to tell him which.
3085
2964
 
3086
2965
def adapt_modules(mods_list, adapter, loader, suite):
3087
2966
    """Adapt the modules in mods_list using adapter and add to suite."""
3088
 
    tests = loader.loadTestsFromModuleNames(mods_list)
3089
 
    adapt_tests(tests, adapter, suite)
3090
 
 
3091
 
 
3092
 
def adapt_tests(tests_list, adapter, suite):
 
2967
    for test in iter_suite_tests(loader.loadTestsFromModuleNames(mods_list)):
 
2968
        suite.addTests(adapter.adapt(test))
 
2969
 
 
2970
 
 
2971
def adapt_tests(tests_list, adapter, loader, suite):
3093
2972
    """Adapt the tests in tests_list using adapter and add to suite."""
3094
 
    for test in iter_suite_tests(tests_list):
3095
 
        suite.addTests(adapter.adapt(test))
 
2973
    for test in tests_list:
 
2974
        suite.addTests(adapter.adapt(loader.loadTestsFromName(test)))
3096
2975
 
3097
2976
 
3098
2977
def _rmtree_temp_dir(dirname):
3179
3058
OsFifoFeature = _OsFifoFeature()
3180
3059
 
3181
3060
 
3182
 
class _UnicodeFilenameFeature(Feature):
3183
 
    """Does the filesystem support Unicode filenames?"""
3184
 
 
3185
 
    def _probe(self):
3186
 
        try:
3187
 
            # Check for character combinations unlikely to be covered by any
3188
 
            # single non-unicode encoding. We use the characters
3189
 
            # - greek small letter alpha (U+03B1) and
3190
 
            # - braille pattern dots-123456 (U+283F).
3191
 
            os.stat(u'\u03b1\u283f')
3192
 
        except UnicodeEncodeError:
3193
 
            return False
3194
 
        except (IOError, OSError):
3195
 
            # The filesystem allows the Unicode filename but the file doesn't
3196
 
            # exist.
3197
 
            return True
3198
 
        else:
3199
 
            # The filesystem allows the Unicode filename and the file exists,
3200
 
            # for some reason.
3201
 
            return True
3202
 
 
3203
 
UnicodeFilenameFeature = _UnicodeFilenameFeature()
3204
 
 
3205
 
 
3206
3061
class TestScenarioApplier(object):
3207
3062
    """A tool to apply scenarios to tests."""
3208
3063
 
3241
3096
    possible_vals = [u'm\xb5', u'\xe1', u'\u0410']
3242
3097
    for uni_val in possible_vals:
3243
3098
        try:
3244
 
            str_val = uni_val.encode(osutils.get_user_encoding())
 
3099
            str_val = uni_val.encode(bzrlib.user_encoding)
3245
3100
        except UnicodeEncodeError:
3246
3101
            # Try a different character
3247
3102
            pass
3285
3140
FTPServerFeature = _FTPServerFeature()
3286
3141
 
3287
3142
 
3288
 
class _UnicodeFilename(Feature):
3289
 
    """Does the filesystem support Unicode filenames?"""
3290
 
 
3291
 
    def _probe(self):
3292
 
        try:
3293
 
            os.stat(u'\u03b1')
3294
 
        except UnicodeEncodeError:
3295
 
            return False
3296
 
        except (IOError, OSError):
3297
 
            # The filesystem allows the Unicode filename but the file doesn't
3298
 
            # exist.
3299
 
            return True
3300
 
        else:
3301
 
            # The filesystem allows the Unicode filename and the file exists,
3302
 
            # for some reason.
3303
 
            return True
3304
 
 
3305
 
UnicodeFilename = _UnicodeFilename()
3306
 
 
3307
 
 
3308
 
class _UTF8Filesystem(Feature):
3309
 
    """Is the filesystem UTF-8?"""
3310
 
 
3311
 
    def _probe(self):
3312
 
        if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
3313
 
            return True
3314
 
        return False
3315
 
 
3316
 
UTF8Filesystem = _UTF8Filesystem()
3317
 
 
3318
 
 
3319
3143
class _CaseInsensitiveFilesystemFeature(Feature):
3320
 
    """Check if underlying filesystem is case-insensitive
 
3144
    """Check if underlined filesystem is case-insensitive
3321
3145
    (e.g. on Windows, Cygwin, MacOS)
3322
3146
    """
3323
3147