~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
                          TestCaseWithTransport,
48
48
                          TestSkipped,
49
49
                          TestSuite,
 
50
                          TestUtil,
50
51
                          TextTestRunner,
51
52
                          UnavailableFeature,
52
53
                          clean_selftest_output,
 
54
                          iter_suite_tests,
 
55
                          filter_suite_by_re,
 
56
                          sort_suite_by_re,
 
57
                          test_suite
53
58
                          )
54
59
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
55
60
from bzrlib.tests.TestUtil import _load_module_by_name
193
198
        from bzrlib.bzrdir import BzrDirTestProviderAdapter
194
199
        input_test = TestBzrDirProviderAdapter(
195
200
            "test_adapted_tests")
 
201
        vfs_factory = "v"
196
202
        server1 = "a"
197
203
        server2 = "b"
198
204
        formats = ["c", "d"]
199
 
        adapter = BzrDirTestProviderAdapter(server1, server2, formats)
 
205
        adapter = BzrDirTestProviderAdapter(vfs_factory,
 
206
            server1, server2, formats)
200
207
        suite = adapter.adapt(input_test)
201
208
        tests = list(iter(suite))
202
209
        self.assertEqual(2, len(tests))
203
210
        self.assertEqual(tests[0].bzrdir_format, formats[0])
 
211
        self.assertEqual(tests[0].vfs_transport_factory, vfs_factory)
204
212
        self.assertEqual(tests[0].transport_server, server1)
205
213
        self.assertEqual(tests[0].transport_readonly_server, server2)
206
214
        self.assertEqual(tests[1].bzrdir_format, formats[1])
 
215
        self.assertEqual(tests[1].vfs_transport_factory, vfs_factory)
207
216
        self.assertEqual(tests[1].transport_server, server1)
208
217
        self.assertEqual(tests[1].transport_readonly_server, server2)
209
218
 
233
242
        self.assertEqual(tests[1].transport_server, server1)
234
243
        self.assertEqual(tests[1].transport_readonly_server, server2)
235
244
 
 
245
    def test_setting_vfs_transport(self):
 
246
        """The vfs_transport_factory can be set optionally."""
 
247
        from bzrlib.repository import RepositoryTestProviderAdapter
 
248
        input_test = TestRepositoryProviderAdapter(
 
249
            "test_adapted_tests")
 
250
        formats = [("c", "C")]
 
251
        adapter = RepositoryTestProviderAdapter(None, None, formats,
 
252
            vfs_transport_factory="vfs")
 
253
        suite = adapter.adapt(input_test)
 
254
        tests = list(iter(suite))
 
255
        self.assertEqual(1, len(tests))
 
256
        self.assertEqual(tests[0].vfs_transport_factory, "vfs")
 
257
 
236
258
 
237
259
class TestInterRepositoryProviderAdapter(TestCase):
238
260
    """A group of tests that test the InterRepository test adapter."""
739
761
        result.report_known_failure(test, err)
740
762
        output = result_stream.getvalue()[prefix:]
741
763
        lines = output.splitlines()
742
 
        self.assertEqual(lines, ['XFAIL                   0ms', '    foo'])
743
 
    
 
764
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
 
765
        self.assertEqual(lines[1], '    foo')
 
766
        self.assertEqual(2, len(lines))
 
767
 
744
768
    def test_text_report_known_failure(self):
745
769
        # text test output formatting
746
770
        pb = MockProgress()
933
957
        stream = StringIO()
934
958
        runner = TextTestRunner(stream=stream)
935
959
        result = self.run_test_runner(runner, test)
936
 
        self.assertEqual(
937
 
            '\n'
938
 
            '----------------------------------------------------------------------\n'
939
 
            'Ran 1 test in 0.000s\n'
940
 
            '\n'
941
 
            'OK (known_failures=1)\n',
942
 
            stream.getvalue())
 
960
        self.assertContainsRe(stream.getvalue(),
 
961
            '\n'
 
962
            '-*\n'
 
963
            'Ran 1 test in .*\n'
 
964
            '\n'
 
965
            'OK \\(known_failures=1\\)\n')
943
966
 
944
967
    def test_skipped_test(self):
945
968
        # run a test that is skipped, and check the suite as a whole still
1488
1511
        feature = Feature()
1489
1512
        exception = UnavailableFeature(feature)
1490
1513
        self.assertIs(feature, exception.args[0])
 
1514
 
 
1515
 
 
1516
class TestSelftestFiltering(TestCase):
 
1517
 
 
1518
    def setUp(self):
 
1519
        self.suite = TestUtil.TestSuite()
 
1520
        self.loader = TestUtil.TestLoader()
 
1521
        self.suite.addTest(self.loader.loadTestsFromModuleNames([
 
1522
            'bzrlib.tests.test_selftest']))
 
1523
        self.all_names = [t.id() for t in iter_suite_tests(self.suite)]
 
1524
 
 
1525
    def test_filter_suite_by_re(self):
 
1526
        filtered_suite = filter_suite_by_re(self.suite, 'test_filter')
 
1527
        filtered_names = [t.id() for t in iter_suite_tests(filtered_suite)]
 
1528
        self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
 
1529
            'TestSelftestFiltering.test_filter_suite_by_re'])
 
1530
            
 
1531
    def test_sort_suite_by_re(self):
 
1532
        sorted_suite = sort_suite_by_re(self.suite, 'test_filter')
 
1533
        sorted_names = [t.id() for t in iter_suite_tests(sorted_suite)]
 
1534
        self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.'
 
1535
            'TestSelftestFiltering.test_filter_suite_by_re')
 
1536
        self.assertEquals(sorted(self.all_names), sorted(sorted_names))
 
1537