~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Upgraded to the latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
                          TestSuite,
50
50
                          TextTestRunner,
51
51
                          UnavailableFeature,
 
52
                          clean_selftest_output,
52
53
                          )
53
54
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
54
55
from bzrlib.tests.TestUtil import _load_module_by_name
192
193
        from bzrlib.bzrdir import BzrDirTestProviderAdapter
193
194
        input_test = TestBzrDirProviderAdapter(
194
195
            "test_adapted_tests")
 
196
        vfs_factory = "v"
195
197
        server1 = "a"
196
198
        server2 = "b"
197
199
        formats = ["c", "d"]
198
 
        adapter = BzrDirTestProviderAdapter(server1, server2, formats)
 
200
        adapter = BzrDirTestProviderAdapter(vfs_factory,
 
201
            server1, server2, formats)
199
202
        suite = adapter.adapt(input_test)
200
203
        tests = list(iter(suite))
201
204
        self.assertEqual(2, len(tests))
202
205
        self.assertEqual(tests[0].bzrdir_format, formats[0])
 
206
        self.assertEqual(tests[0].vfs_transport_factory, vfs_factory)
203
207
        self.assertEqual(tests[0].transport_server, server1)
204
208
        self.assertEqual(tests[0].transport_readonly_server, server2)
205
209
        self.assertEqual(tests[1].bzrdir_format, formats[1])
 
210
        self.assertEqual(tests[1].vfs_transport_factory, vfs_factory)
206
211
        self.assertEqual(tests[1].transport_server, server1)
207
212
        self.assertEqual(tests[1].transport_readonly_server, server2)
208
213
 
232
237
        self.assertEqual(tests[1].transport_server, server1)
233
238
        self.assertEqual(tests[1].transport_readonly_server, server2)
234
239
 
 
240
    def test_setting_vfs_transport(self):
 
241
        """The vfs_transport_factory can be set optionally."""
 
242
        from bzrlib.repository import RepositoryTestProviderAdapter
 
243
        input_test = TestRepositoryProviderAdapter(
 
244
            "test_adapted_tests")
 
245
        formats = [("c", "C")]
 
246
        adapter = RepositoryTestProviderAdapter(None, None, formats,
 
247
            vfs_transport_factory="vfs")
 
248
        suite = adapter.adapt(input_test)
 
249
        tests = list(iter(suite))
 
250
        self.assertEqual(1, len(tests))
 
251
        self.assertEqual(tests[0].vfs_transport_factory, "vfs")
 
252
 
235
253
 
236
254
class TestInterRepositoryProviderAdapter(TestCase):
237
255
    """A group of tests that test the InterRepository test adapter."""
738
756
        result.report_known_failure(test, err)
739
757
        output = result_stream.getvalue()[prefix:]
740
758
        lines = output.splitlines()
741
 
        self.assertEqual(lines, ['XFAIL                   0ms', '    foo'])
742
 
    
 
759
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
 
760
        self.assertEqual(lines[1], '    foo')
 
761
        self.assertEqual(2, len(lines))
 
762
 
743
763
    def test_text_report_known_failure(self):
744
764
        # text test output formatting
745
765
        pb = MockProgress()
932
952
        stream = StringIO()
933
953
        runner = TextTestRunner(stream=stream)
934
954
        result = self.run_test_runner(runner, test)
935
 
        self.assertEqual(
936
 
            '\n'
937
 
            '----------------------------------------------------------------------\n'
938
 
            'Ran 1 test in 0.000s\n'
939
 
            '\n'
940
 
            'OK (known_failures=1)\n',
941
 
            stream.getvalue())
 
955
        self.assertContainsRe(stream.getvalue(),
 
956
            '\n'
 
957
            '-*\n'
 
958
            'Ran 1 test in .*\n'
 
959
            '\n'
 
960
            'OK \\(known_failures=1\\)\n')
942
961
 
943
962
    def test_skipped_test(self):
944
963
        # run a test that is skipped, and check the suite as a whole still
1162
1181
        """The bzrlib hooks should be sanitised by setUp."""
1163
1182
        self.assertEqual(bzrlib.branch.BranchHooks(),
1164
1183
            bzrlib.branch.Branch.hooks)
 
1184
        self.assertEqual(bzrlib.smart.server.SmartServerHooks(),
 
1185
            bzrlib.smart.server.SmartTCPServer.hooks)
1165
1186
 
1166
1187
    def test__gather_lsprof_in_benchmarks(self):
1167
1188
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.
1394
1415
 
1395
1416
    def test_clean_output(self):
1396
1417
        # test functionality of clean_selftest_output()
1397
 
        from bzrlib.tests import clean_selftest_output
1398
 
 
1399
 
        dirs = ('test0000.tmp', 'test0001.tmp', 'bzrlib', 'tests')
1400
 
        files = ('bzr', 'setup.py', 'test9999.tmp')
1401
 
        for i in dirs:
1402
 
            os.mkdir(i)
1403
 
        for i in files:
1404
 
            f = file(i, 'wb')
1405
 
            f.write('content of ')
1406
 
            f.write(i)
1407
 
            f.close()
 
1418
        self.build_tree(['test0000.tmp/', 'test0001.tmp/',
 
1419
                         'bzrlib/', 'tests/',
 
1420
                         'bzr', 'setup.py', 'test9999.tmp'])
1408
1421
 
1409
1422
        root = os.getcwdu()
1410
1423
        before = os.listdir(root)
1420
1433
                           'test9999.tmp','tests'],
1421
1434
                           after)
1422
1435
 
 
1436
    def test_clean_readonly(self):
 
1437
        # test for delete read-only files
 
1438
        self.build_tree(['test0000.tmp/', 'test0000.tmp/foo'])
 
1439
        osutils.make_readonly('test0000.tmp/foo')
 
1440
        root = os.getcwdu()
 
1441
        before = os.listdir(root);  before.sort()
 
1442
        self.assertEquals(['test0000.tmp'], before)
 
1443
        clean_selftest_output(root, quiet=True)
 
1444
        after = os.listdir(root);   after.sort()
 
1445
        self.assertEquals([], after)
 
1446
 
1423
1447
 
1424
1448
class TestKnownFailure(TestCase):
1425
1449
 
1429
1453
        # runners.
1430
1454
        self.assertIsInstance(KnownFailure(""), AssertionError)
1431
1455
 
 
1456
    def test_expect_failure(self):
 
1457
        try:
 
1458
            self.expectFailure("Doomed to failure", self.assertTrue, False)
 
1459
        except KnownFailure, e:
 
1460
            self.assertEqual('Doomed to failure', e.args[0])
 
1461
        try:
 
1462
            self.expectFailure("Doomed to failure", self.assertTrue, True)
 
1463
        except AssertionError, e:
 
1464
            self.assertEqual('Unexpected success.  Should have failed:'
 
1465
                             ' Doomed to failure', e.args[0])
 
1466
        else:
 
1467
            self.fail('Assertion not raised')
 
1468
 
1432
1469
 
1433
1470
class TestFeature(TestCase):
1434
1471