/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: Martin Albisetti
  • Date: 2008-04-08 22:51:37 UTC
  • mfrom: (3346 +trunk)
  • mto: (3350.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 3351.
  • Revision ID: argentina@gmail.com-20080408225137-uynl9dxtsdpi8nl9
Merge from bzr.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.
418
402
        self.pb.update('[test 0/%d] starting...' % (self.num_tests))
419
403
 
420
404
    def _progress_prefix_text(self):
421
 
        a = '[%d' % self.count
 
405
        # the longer this text, the less space we have to show the test
 
406
        # name...
 
407
        a = '[%d' % self.count              # total that have been run
 
408
        # tests skipped as known not to be relevant are not important enough
 
409
        # to show here
 
410
        ## if self.skip_count:
 
411
        ##     a += ', %d skip' % self.skip_count
 
412
        ## if self.known_failure_count:
 
413
        ##     a += '+%dX' % self.known_failure_count
422
414
        if self.num_tests is not None:
423
415
            a +='/%d' % self.num_tests
424
 
        a += ' in %ds' % (time.time() - self._overall_start_time)
 
416
        a += ' in '
 
417
        runtime = time.time() - self._overall_start_time
 
418
        if runtime >= 60:
 
419
            a += '%dm%ds' % (runtime / 60, runtime % 60)
 
420
        else:
 
421
            a += '%ds' % runtime
425
422
        if self.error_count:
426
 
            a += ', %d errors' % self.error_count
 
423
            a += ', %d err' % self.error_count
427
424
        if self.failure_count:
428
 
            a += ', %d failed' % self.failure_count
429
 
        if self.known_failure_count:
430
 
            a += ', %d known failures' % self.known_failure_count
431
 
        if self.skip_count:
432
 
            a += ', %d skipped' % self.skip_count
 
425
            a += ', %d fail' % self.failure_count
433
426
        if self.unsupported:
434
 
            a += ', %d missing features' % len(self.unsupported)
 
427
            a += ', %d missing' % len(self.unsupported)
435
428
        a += ']'
436
429
        return a
437
430
 
826
819
        import bzrlib.smart.server
827
820
        self._preserved_hooks = {
828
821
            bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
 
822
            bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
829
823
            bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
830
824
            }
831
825
        self.addCleanup(self._restoreHooks)
2283
2277
def condition_id_in_list(id_list):
2284
2278
    """Create a condition filter which verify that test's id in a list.
2285
2279
    
2286
 
    :param name: A TestIdList object.
 
2280
    :param id_list: A TestIdList object.
2287
2281
    :return: A callable that returns True if the test's id appears in the list.
2288
2282
    """
2289
2283
    def condition(test):
2290
 
        return id_list.test_in(test.id())
 
2284
        return id_list.includes(test.id())
2291
2285
    return condition
2292
2286
 
2293
2287
 
2659
2653
                modules[mod_name] = True
2660
2654
        self.modules = modules
2661
2655
 
2662
 
    def is_module_name_used(self, module_name):
 
2656
    def refers_to(self, module_name):
2663
2657
        """Is there tests for the module or one of its sub modules."""
2664
2658
        return self.modules.has_key(module_name)
2665
2659
 
2666
 
    def test_in(self, test_id):
 
2660
    def includes(self, test_id):
2667
2661
        return self.tests.has_key(test_id)
2668
2662
 
2669
2663
 
2742
2736
                   'bzrlib.tests.test_missing',
2743
2737
                   'bzrlib.tests.test_msgeditor',
2744
2738
                   'bzrlib.tests.test_multiparent',
 
2739
                   'bzrlib.tests.test_mutabletree',
2745
2740
                   'bzrlib.tests.test_nonascii',
2746
2741
                   'bzrlib.tests.test_options',
2747
2742
                   'bzrlib.tests.test_osutils',
2810
2805
        'bzrlib.tests.test_transport_implementations',
2811
2806
        'bzrlib.tests.test_read_bundle',
2812
2807
        ]
2813
 
    suite = TestUtil.TestSuite()
2814
2808
    loader = TestUtil.TestLoader()
2815
2809
 
2816
 
    if keep_only is not None:
 
2810
    if keep_only is None:
 
2811
        loader = TestUtil.TestLoader()
 
2812
    else:
2817
2813
        id_filter = TestIdList(keep_only)
 
2814
        loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
 
2815
    suite = loader.suiteClass()
2818
2816
 
2819
2817
    # 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)
 
2818
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2828
2819
 
2829
2820
    # modules adapted for transport implementations
2830
2821
    from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2831
2822
    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)
 
2823
    adapt_modules(test_transport_implementations, adapter, loader, suite)
2841
2824
 
2842
2825
    # modules defining their own test_suite()
2843
2826
    for package in [p for p in packages_to_test()
2844
2827
                    if (keep_only is None
2845
 
                        or id_filter.is_module_name_used(p.__name__))]:
 
2828
                        or id_filter.refers_to(p.__name__))]:
2846
2829
        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
2830
        suite.addTest(pack_suite)
2850
2831
 
2851
 
    for mod in MODULES_TO_DOCTEST:
 
2832
    modules_to_doctest = [
 
2833
        'bzrlib',
 
2834
        'bzrlib.errors',
 
2835
        'bzrlib.export',
 
2836
        'bzrlib.inventory',
 
2837
        'bzrlib.iterablefile',
 
2838
        'bzrlib.lockdir',
 
2839
        'bzrlib.merge3',
 
2840
        'bzrlib.option',
 
2841
        'bzrlib.store',
 
2842
        'bzrlib.tests',
 
2843
        'bzrlib.timestamp',
 
2844
        'bzrlib.version_info_formats.format_custom',
 
2845
        ]
 
2846
 
 
2847
    for mod in modules_to_doctest:
 
2848
        if not (keep_only is None or id_filter.refers_to(mod)):
 
2849
            # No tests to keep here, move along
 
2850
            continue
2852
2851
        try:
2853
2852
            doc_suite = doctest.DocTestSuite(mod)
2854
2853
        except ValueError, e:
2855
2854
            print '**failed to get doctest for: %s\n%s' % (mod, e)
2856
2855
            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
2856
        suite.addTest(doc_suite)
2861
2857
 
2862
2858
    default_encoding = sys.getdefaultencoding()
2863
2859
    for name, plugin in bzrlib.plugin.plugins().items():
2864
2860
        if keep_only is not None:
2865
 
            if not id_filter.is_module_name_used(plugin.module.__name__):
 
2861
            if not id_filter.refers_to(plugin.module.__name__):
2866
2862
                continue
2867
2863
        plugin_suite = plugin.test_suite()
2868
2864
        # We used to catch ImportError here and turn it into just a warning,
2869
2865
        # but really if you don't have --no-plugins this should be a failure.
2870
2866
        # mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
 
2867
        if plugin_suite is None:
 
2868
            plugin_suite = plugin.load_plugin_tests(loader)
2871
2869
        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
2870
            suite.addTest(plugin_suite)
2876
2871
        if default_encoding != sys.getdefaultencoding():
2877
2872
            bzrlib.trace.warning(
2881
2876
            sys.setdefaultencoding(default_encoding)
2882
2877
 
2883
2878
    if keep_only is not None:
 
2879
        # Now that the referred modules have loaded their tests, keep only the
 
2880
        # requested ones.
 
2881
        suite = filter_suite_by_id_list(suite, id_filter)
2884
2882
        # Do some sanity checks on the id_list filtering
2885
2883
        not_found, duplicates = suite_matches_id_list(suite, keep_only)
2886
2884
        for id in not_found: