~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-12 11:57:43 UTC
  • mfrom: (3426.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080512115743-6uz3lnmrrbhmoiqe
(vila) Adding --starting-with <test_id> option to selftest makes it
        run faster on selective loading

Show diffs side-by-side

added added

removed removed

Lines of Context:
1749
1749
        re_filtered = filter_suite_by_re(self.suite, my_pattern)
1750
1750
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1751
1751
 
 
1752
    def test_condition_id_startswith(self):
 
1753
        klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
 
1754
        start = klass + 'test_condition_id_starts'
 
1755
        test_names = [klass + 'test_condition_id_startswith']
 
1756
        filtered_suite = filter_suite_by_condition(
 
1757
            self.suite, tests.condition_id_startswith(start))
 
1758
        my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
 
1759
        re_filtered = filter_suite_by_re(self.suite, my_pattern)
 
1760
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
 
1761
 
1752
1762
    def test_condition_isinstance(self):
1753
1763
        filtered_suite = filter_suite_by_condition(self.suite,
1754
1764
            condition_isinstance(self.__class__))
1804
1814
            ['bzrlib.tests.test_selftest.'
1805
1815
             'TestSelftestFiltering.test_filter_suite_by_id_list'])
1806
1816
 
 
1817
    def test_filter_suite_by_id_startswith(self):
 
1818
        # By design this test may fail if another test is added whose name also
 
1819
        # begins with the start value used.
 
1820
        klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
 
1821
        start = klass + 'test_filter_suite_by_id_starts'
 
1822
        test_list = [klass + 'test_filter_suite_by_id_startswith']
 
1823
        filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
 
1824
        filtered_names = _test_ids(filtered_suite)
 
1825
        self.assertEqual(
 
1826
            filtered_names,
 
1827
            ['bzrlib.tests.test_selftest.'
 
1828
             'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
 
1829
 
1807
1830
    def test_preserve_input(self):
1808
1831
        # NB: Surely this is something in the stdlib to do this?
1809
1832
        self.assertTrue(self.suite is preserve_input(self.suite))
2084
2107
 
2085
2108
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2086
2109
        self.assertEquals([], _test_ids(suite))
 
2110
 
 
2111
 
 
2112
class TestFilteredByNameStartTestLoader(tests.TestCase):
 
2113
 
 
2114
    def _create_loader(self, name_start):
 
2115
        def needs_module(name):
 
2116
            return name.startswith(name_start) or name_start.startswith(name)
 
2117
        loader = TestUtil.FilteredByModuleTestLoader(needs_module)
 
2118
        return loader
 
2119
 
 
2120
    def test_load_tests(self):
 
2121
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
 
2122
        loader = self._create_loader('bzrlib.tests.test_samp')
 
2123
 
 
2124
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2125
        self.assertEquals(test_list, _test_ids(suite))
 
2126
 
 
2127
    def test_load_tests_inside_module(self):
 
2128
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
 
2129
        loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
 
2130
 
 
2131
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2132
        self.assertEquals(test_list, _test_ids(suite))
 
2133
 
 
2134
    def test_exclude_tests(self):
 
2135
        test_list = ['bogus']
 
2136
        loader = self._create_loader('bogus')
 
2137
 
 
2138
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2139
        self.assertEquals([], _test_ids(suite))