/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: Robert Collins
  • Date: 2008-04-07 04:54:52 UTC
  • mfrom: (3340 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3350.
  • Revision ID: robertc@robertcollins.net-20080407045452-8r6asf9hs0cl5jvy
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 
110
110
default_transport = LocalURLServer
111
111
 
112
 
MODULES_TO_DOCTEST = [
113
 
        bzrlib,
114
 
        bzrlib.timestamp,
115
 
        bzrlib.errors,
116
 
        bzrlib.export,
117
 
        bzrlib.inventory,
118
 
        bzrlib.iterablefile,
119
 
        bzrlib.lockdir,
120
 
        bzrlib.merge3,
121
 
        bzrlib.option,
122
 
        bzrlib.store,
123
 
        bzrlib.version_info_formats.format_custom,
124
 
        # quoted to avoid module-loading circularity
125
 
        'bzrlib.tests',
126
 
        ]
127
 
 
128
112
 
129
113
def packages_to_test():
130
114
    """Return a list of packages to test.
826
810
        import bzrlib.smart.server
827
811
        self._preserved_hooks = {
828
812
            bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
 
813
            bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
829
814
            bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
830
815
            }
831
816
        self.addCleanup(self._restoreHooks)
2283
2268
def condition_id_in_list(id_list):
2284
2269
    """Create a condition filter which verify that test's id in a list.
2285
2270
    
2286
 
    :param name: A TestIdList object.
 
2271
    :param id_list: A TestIdList object.
2287
2272
    :return: A callable that returns True if the test's id appears in the list.
2288
2273
    """
2289
2274
    def condition(test):
2290
 
        return id_list.test_in(test.id())
 
2275
        return id_list.includes(test.id())
2291
2276
    return condition
2292
2277
 
2293
2278
 
2659
2644
                modules[mod_name] = True
2660
2645
        self.modules = modules
2661
2646
 
2662
 
    def is_module_name_used(self, module_name):
 
2647
    def refers_to(self, module_name):
2663
2648
        """Is there tests for the module or one of its sub modules."""
2664
2649
        return self.modules.has_key(module_name)
2665
2650
 
2666
 
    def test_in(self, test_id):
 
2651
    def includes(self, test_id):
2667
2652
        return self.tests.has_key(test_id)
2668
2653
 
2669
2654
 
2742
2727
                   'bzrlib.tests.test_missing',
2743
2728
                   'bzrlib.tests.test_msgeditor',
2744
2729
                   'bzrlib.tests.test_multiparent',
 
2730
                   'bzrlib.tests.test_mutabletree',
2745
2731
                   'bzrlib.tests.test_nonascii',
2746
2732
                   'bzrlib.tests.test_options',
2747
2733
                   'bzrlib.tests.test_osutils',
2810
2796
        'bzrlib.tests.test_transport_implementations',
2811
2797
        'bzrlib.tests.test_read_bundle',
2812
2798
        ]
2813
 
    suite = TestUtil.TestSuite()
2814
2799
    loader = TestUtil.TestLoader()
2815
2800
 
2816
 
    if keep_only is not None:
 
2801
    if keep_only is None:
 
2802
        loader = TestUtil.TestLoader()
 
2803
    else:
2817
2804
        id_filter = TestIdList(keep_only)
 
2805
        loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
 
2806
    suite = loader.suiteClass()
2818
2807
 
2819
2808
    # modules building their suite with loadTestsFromModuleNames
2820
 
    if keep_only is None:
2821
 
        suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2822
 
    else:
2823
 
        for mod in [m for m in testmod_names
2824
 
                    if id_filter.is_module_name_used(m)]:
2825
 
            mod_suite = loader.loadTestsFromModuleNames([mod])
2826
 
            mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2827
 
            suite.addTest(mod_suite)
 
2809
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2828
2810
 
2829
2811
    # modules adapted for transport implementations
2830
2812
    from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2831
2813
    adapter = TransportTestProviderAdapter()
2832
 
    if keep_only is None:
2833
 
        adapt_modules(test_transport_implementations, adapter, loader, suite)
2834
 
    else:
2835
 
        for mod in [m for m in test_transport_implementations
2836
 
                    if id_filter.is_module_name_used(m)]:
2837
 
            mod_suite = TestUtil.TestSuite()
2838
 
            adapt_modules([mod], adapter, loader, mod_suite)
2839
 
            mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2840
 
            suite.addTest(mod_suite)
 
2814
    adapt_modules(test_transport_implementations, adapter, loader, suite)
2841
2815
 
2842
2816
    # modules defining their own test_suite()
2843
2817
    for package in [p for p in packages_to_test()
2844
2818
                    if (keep_only is None
2845
 
                        or id_filter.is_module_name_used(p.__name__))]:
 
2819
                        or id_filter.refers_to(p.__name__))]:
2846
2820
        pack_suite = package.test_suite()
2847
 
        if keep_only is not None:
2848
 
            pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2849
2821
        suite.addTest(pack_suite)
2850
2822
 
2851
 
    for mod in MODULES_TO_DOCTEST:
 
2823
    modules_to_doctest = [
 
2824
        'bzrlib',
 
2825
        'bzrlib.errors',
 
2826
        'bzrlib.export',
 
2827
        'bzrlib.inventory',
 
2828
        'bzrlib.iterablefile',
 
2829
        'bzrlib.lockdir',
 
2830
        'bzrlib.merge3',
 
2831
        'bzrlib.option',
 
2832
        'bzrlib.store',
 
2833
        'bzrlib.tests',
 
2834
        'bzrlib.timestamp',
 
2835
        'bzrlib.version_info_formats.format_custom',
 
2836
        ]
 
2837
 
 
2838
    for mod in modules_to_doctest:
 
2839
        if not (keep_only is None or id_filter.refers_to(mod)):
 
2840
            # No tests to keep here, move along
 
2841
            continue
2852
2842
        try:
2853
2843
            doc_suite = doctest.DocTestSuite(mod)
2854
2844
        except ValueError, e:
2855
2845
            print '**failed to get doctest for: %s\n%s' % (mod, e)
2856
2846
            raise
2857
 
        if keep_only is not None:
2858
 
            # DocTests may use ids which doesn't contain the module name
2859
 
            doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2860
2847
        suite.addTest(doc_suite)
2861
2848
 
2862
2849
    default_encoding = sys.getdefaultencoding()
2863
2850
    for name, plugin in bzrlib.plugin.plugins().items():
2864
2851
        if keep_only is not None:
2865
 
            if not id_filter.is_module_name_used(plugin.module.__name__):
 
2852
            if not id_filter.refers_to(plugin.module.__name__):
2866
2853
                continue
2867
2854
        plugin_suite = plugin.test_suite()
2868
2855
        # We used to catch ImportError here and turn it into just a warning,
2869
2856
        # but really if you don't have --no-plugins this should be a failure.
2870
2857
        # mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
 
2858
        if plugin_suite is None:
 
2859
            plugin_suite = plugin.load_plugin_tests(loader)
2871
2860
        if plugin_suite is not None:
2872
 
            if keep_only is not None:
2873
 
                plugin_suite = filter_suite_by_id_list(plugin_suite,
2874
 
                                                       id_filter)
2875
2861
            suite.addTest(plugin_suite)
2876
2862
        if default_encoding != sys.getdefaultencoding():
2877
2863
            bzrlib.trace.warning(
2881
2867
            sys.setdefaultencoding(default_encoding)
2882
2868
 
2883
2869
    if keep_only is not None:
 
2870
        # Now that the referred modules have loaded their tests, keep only the
 
2871
        # requested ones.
 
2872
        suite = filter_suite_by_id_list(suite, id_filter)
2884
2873
        # Do some sanity checks on the id_list filtering
2885
2874
        not_found, duplicates = suite_matches_id_list(suite, keep_only)
2886
2875
        for id in not_found: