/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/test_selftest.py

Update to bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    """
127
127
 
128
128
    def test_get_transport_permutations(self):
129
 
        # this checks that we the module get_test_permutations call
130
 
        # is made by the adapter get_transport_test_permitations method.
 
129
        # this checks that get_test_permutations defined by the module is
 
130
        # called by the adapter get_transport_test_permutations method.
131
131
        class MockModule(object):
132
132
            def get_test_permutations(self):
133
133
                return sample_permutation
139
139
                         adapter.get_transport_test_permutations(MockModule()))
140
140
 
141
141
    def test_adapter_checks_all_modules(self):
142
 
        # this checks that the adapter returns as many permurtations as
143
 
        # there are in all the registered# transport modules for there
144
 
        # - we assume if this matches its probably doing the right thing
145
 
        # especially in combination with the tests for setting the right
146
 
        # classes below.
 
142
        # this checks that the adapter returns as many permutations as there
 
143
        # are in all the registered transport modules - we assume if this
 
144
        # matches its probably doing the right thing especially in combination
 
145
        # with the tests for setting the right classes below.
147
146
        from bzrlib.tests.test_transport_implementations \
148
147
            import TransportTestProviderAdapter
149
148
        from bzrlib.transport import _get_transport_modules
235
234
            adapter.scenarios)
236
235
 
237
236
 
238
 
class TestRepositoryProviderAdapter(TestCase):
 
237
class TestRepositoryParameterisation(TestCase):
239
238
    """A group of tests that test the repository implementation test adapter."""
240
239
 
241
 
    def test_constructor(self):
242
 
        # check that constructor parameters are passed through to the
243
 
        # scenarios.
244
 
        from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
245
 
        server1 = "a"
246
 
        server2 = "b"
247
 
        formats = [("c", "C"), ("d", "D")]
248
 
        adapter = RepositoryTestProviderAdapter(server1, server2, formats)
249
 
        self.assertEqual([
250
 
            ('str',
251
 
             {'bzrdir_format': 'C',
252
 
              'repository_format': 'c',
253
 
              'transport_readonly_server': 'b',
254
 
              'transport_server': 'a'}),
255
 
            ('str',
256
 
             {'bzrdir_format': 'D',
257
 
              'repository_format': 'd',
258
 
              'transport_readonly_server': 'b',
259
 
              'transport_server': 'a'})],
260
 
            adapter.scenarios)
261
 
 
262
240
    def test_setting_vfs_transport(self):
263
241
        """The vfs_transport_factory can be set optionally."""
264
 
        from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
265
 
        formats = [("a", "b"), ("c", "d")]
266
 
        adapter = RepositoryTestProviderAdapter(None, None, formats,
 
242
        from bzrlib.tests.repository_implementations import formats_to_scenarios
 
243
        scenarios = formats_to_scenarios(
 
244
            [("a", "b"), ("c", "d")],
 
245
            None,
 
246
            None,
267
247
            vfs_transport_factory="vfs")
268
248
        self.assertEqual([
269
249
            ('str',
278
258
              'transport_readonly_server': None,
279
259
              'transport_server': None,
280
260
              'vfs_transport_factory': 'vfs'})],
281
 
            adapter.scenarios)
 
261
            scenarios)
282
262
 
283
263
    def test_formats_to_scenarios(self):
284
264
        """The adapter can generate all the scenarios needed."""
285
 
        from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
286
 
        no_vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
287
 
            [], None)
288
 
        vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
289
 
            [], vfs_transport_factory="vfs")
 
265
        from bzrlib.tests.repository_implementations import formats_to_scenarios
 
266
        formats = [("c", "C"), (1, "D")]
 
267
        no_vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
 
268
            None)
 
269
        vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
 
270
            vfs_transport_factory="vfs")
290
271
        # no_vfs generate scenarios without vfs_transport_factor
291
 
        formats = [("c", "C"), (1, "D")]
292
272
        self.assertEqual([
293
273
            ('str',
294
274
             {'bzrdir_format': 'C',
300
280
              'repository_format': 1,
301
281
              'transport_readonly_server': 'readonly',
302
282
              'transport_server': 'server'})],
303
 
            no_vfs_adapter.formats_to_scenarios(formats))
 
283
            no_vfs_scenarios)
304
284
        self.assertEqual([
305
285
            ('str',
306
286
             {'bzrdir_format': 'C',
314
294
              'transport_readonly_server': 'readonly',
315
295
              'transport_server': 'server',
316
296
              'vfs_transport_factory': 'vfs'})],
317
 
            vfs_adapter.formats_to_scenarios(formats))
 
297
            vfs_scenarios)
318
298
 
319
299
 
320
300
class TestTestScenarioApplier(TestCase):
995
975
        self.assertEqual(None, result._extractBenchmarkTime(test))
996
976
 
997
977
 
 
978
class TestUnicodeFilenameFeature(TestCase):
 
979
 
 
980
    def test_probe_passes(self):
 
981
        """UnicodeFilenameFeature._probe passes."""
 
982
        # We can't test much more than that because the behaviour depends
 
983
        # on the platform.
 
984
        tests.UnicodeFilenameFeature._probe()
 
985
 
 
986
 
998
987
class TestRunner(TestCase):
999
988
 
1000
989
    def dummy_test(self):
1694
1683
        re_filtered = filter_suite_by_re(self.suite, my_pattern)
1695
1684
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1696
1685
 
 
1686
    def test_condition_id_startswith(self):
 
1687
        klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
 
1688
        start = klass + 'test_condition_id_starts'
 
1689
        test_names = [klass + 'test_condition_id_startswith']
 
1690
        filtered_suite = filter_suite_by_condition(
 
1691
            self.suite, tests.condition_id_startswith(start))
 
1692
        my_pattern = 'TestSelftestFiltering.*test_condition_id_startswith'
 
1693
        re_filtered = filter_suite_by_re(self.suite, my_pattern)
 
1694
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
 
1695
 
1697
1696
    def test_condition_isinstance(self):
1698
1697
        filtered_suite = filter_suite_by_condition(self.suite,
1699
1698
            condition_isinstance(self.__class__))
1749
1748
            ['bzrlib.tests.test_selftest.'
1750
1749
             'TestSelftestFiltering.test_filter_suite_by_id_list'])
1751
1750
 
 
1751
    def test_filter_suite_by_id_startswith(self):
 
1752
        # By design this test may fail if another test is added whose name also
 
1753
        # begins with the start value used.
 
1754
        klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
 
1755
        start = klass + 'test_filter_suite_by_id_starts'
 
1756
        test_list = [klass + 'test_filter_suite_by_id_startswith']
 
1757
        filtered_suite = tests.filter_suite_by_id_startswith(self.suite, start)
 
1758
        filtered_names = _test_ids(filtered_suite)
 
1759
        self.assertEqual(
 
1760
            filtered_names,
 
1761
            ['bzrlib.tests.test_selftest.'
 
1762
             'TestSelftestFiltering.test_filter_suite_by_id_startswith'])
 
1763
 
1752
1764
    def test_preserve_input(self):
1753
1765
        # NB: Surely this is something in the stdlib to do this?
1754
1766
        self.assertTrue(self.suite is preserve_input(self.suite))
2029
2041
 
2030
2042
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2031
2043
        self.assertEquals([], _test_ids(suite))
 
2044
 
 
2045
 
 
2046
class TestFilteredByNameStartTestLoader(tests.TestCase):
 
2047
 
 
2048
    def _create_loader(self, name_start):
 
2049
        def needs_module(name):
 
2050
            return name.startswith(name_start) or name_start.startswith(name)
 
2051
        loader = TestUtil.FilteredByModuleTestLoader(needs_module)
 
2052
        return loader
 
2053
 
 
2054
    def test_load_tests(self):
 
2055
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
 
2056
        loader = self._create_loader('bzrlib.tests.test_samp')
 
2057
 
 
2058
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2059
        self.assertEquals(test_list, _test_ids(suite))
 
2060
 
 
2061
    def test_load_tests_inside_module(self):
 
2062
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
 
2063
        loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
 
2064
 
 
2065
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2066
        self.assertEquals(test_list, _test_ids(suite))
 
2067
 
 
2068
    def test_exclude_tests(self):
 
2069
        test_list = ['bogus']
 
2070
        loader = self._create_loader('bogus')
 
2071
 
 
2072
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
 
2073
        self.assertEquals([], _test_ids(suite))