~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    features,
65
65
    stub_sftp,
66
66
    test_lsprof,
 
67
    test_server,
67
68
    test_sftp_transport,
68
69
    TestUtil,
69
70
    )
70
71
from bzrlib.trace import note
71
 
from bzrlib.transport.memory import MemoryServer, MemoryTransport
 
72
from bzrlib.transport import memory
72
73
from bzrlib.version import _get_bzr_source_tree
73
74
 
74
75
 
622
623
 
623
624
    def test_get_readonly_url_none(self):
624
625
        from bzrlib.transport import get_transport
625
 
        from bzrlib.transport.memory import MemoryServer
626
626
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
627
 
        self.vfs_transport_factory = MemoryServer
 
627
        self.vfs_transport_factory = memory.MemoryServer
628
628
        self.transport_readonly_server = None
629
629
        # calling get_readonly_transport() constructs a decorator on the url
630
630
        # for the server
639
639
    def test_get_readonly_url_http(self):
640
640
        from bzrlib.tests.http_server import HttpServer
641
641
        from bzrlib.transport import get_transport
642
 
        from bzrlib.transport.local import LocalURLServer
643
642
        from bzrlib.transport.http import HttpTransportBase
644
 
        self.transport_server = LocalURLServer
 
643
        self.transport_server = test_server.LocalURLServer
645
644
        self.transport_readonly_server = HttpServer
646
645
        # calling get_readonly_transport() gives us a HTTP server instance.
647
646
        url = self.get_readonly_url()
678
677
 
679
678
    def setUp(self):
680
679
        super(TestTestCaseTransports, self).setUp()
681
 
        self.vfs_transport_factory = MemoryServer
 
680
        self.vfs_transport_factory = memory.MemoryServer
682
681
 
683
682
    def test_make_bzrdir_preserves_transport(self):
684
683
        t = self.get_transport()
685
684
        result_bzrdir = self.make_bzrdir('subdir')
686
685
        self.assertIsInstance(result_bzrdir.transport,
687
 
                              MemoryTransport)
 
686
                              memory.MemoryTransport)
688
687
        # should not be on disk, should only be in memory
689
688
        self.failIfExists('subdir')
690
689
 
755
754
    def _patch_get_bzr_source_tree(self):
756
755
        # Reading from the actual source tree breaks isolation, but we don't
757
756
        # want to assume that thats *all* that would happen.
758
 
        def _get_bzr_source_tree():
759
 
            return None
760
 
        orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
761
 
        bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
762
 
        def restore():
763
 
            bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
764
 
        self.addCleanup(restore)
 
757
        self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
765
758
 
766
759
    def test_assigned_benchmark_file_stores_date(self):
767
760
        self._patch_get_bzr_source_tree()
1202
1195
        # Reading from the actual source tree breaks isolation, but we don't
1203
1196
        # want to assume that thats *all* that would happen.
1204
1197
        self._get_source_tree_calls = []
1205
 
        def _get_bzr_source_tree():
 
1198
        def new_get():
1206
1199
            self._get_source_tree_calls.append("called")
1207
1200
            return None
1208
 
        orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
1209
 
        bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
1210
 
        def restore():
1211
 
            bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
1212
 
        self.addCleanup(restore)
 
1201
        self.overrideAttr(bzrlib.version, '_get_bzr_source_tree',  new_get)
1213
1202
 
1214
1203
    def test_bench_history(self):
1215
1204
        # tests that the running the benchmark passes bench_history into
1323
1312
        self.assertEqual(flags, bzrlib.debug.debug_flags)
1324
1313
 
1325
1314
    def change_selftest_debug_flags(self, new_flags):
1326
 
        orig_selftest_flags = tests.selftest_debug_flags
1327
 
        self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1328
 
        tests.selftest_debug_flags = set(new_flags)
1329
 
 
1330
 
    def _restore_selftest_debug_flags(self, flags):
1331
 
        tests.selftest_debug_flags = flags
 
1315
        self.overrideAttr(tests, 'selftest_debug_flags', set(new_flags))
1332
1316
 
1333
1317
    def test_allow_debug_flag(self):
1334
1318
        """The -Eallow_debug flag prevents bzrlib.debug.debug_flags from being
1485
1469
        # permitted.
1486
1470
        # Manually set one up (TestCase doesn't and shouldn't provide magic
1487
1471
        # machinery)
1488
 
        transport_server = MemoryServer()
 
1472
        transport_server = memory.MemoryServer()
1489
1473
        transport_server.start_server()
1490
1474
        self.addCleanup(transport_server.stop_server)
1491
1475
        t = transport.get_transport(transport_server.get_url())
1573
1557
            result.calls)
1574
1558
 
1575
1559
    def test_start_server_registers_url(self):
1576
 
        transport_server = MemoryServer()
 
1560
        transport_server = memory.MemoryServer()
1577
1561
        # A little strict, but unlikely to be changed soon.
1578
1562
        self.assertEqual([], self._bzr_selftest_roots)
1579
1563
        self.start_server(transport_server)
1635
1619
        self.assertRaises(AssertionError,
1636
1620
            self.assertListRaises, _TestException, success_generator)
1637
1621
 
 
1622
    def test_overrideAttr_without_value(self):
 
1623
        self.test_attr = 'original' # Define a test attribute
 
1624
        obj = self # Make 'obj' visible to the embedded test
 
1625
        class Test(tests.TestCase):
 
1626
 
 
1627
            def setUp(self):
 
1628
                tests.TestCase.setUp(self)
 
1629
                self.orig = self.overrideAttr(obj, 'test_attr')
 
1630
 
 
1631
            def test_value(self):
 
1632
                self.assertEqual('original', self.orig)
 
1633
                self.assertEqual('original', obj.test_attr)
 
1634
                obj.test_attr = 'modified'
 
1635
                self.assertEqual('modified', obj.test_attr)
 
1636
 
 
1637
        test = Test('test_value')
 
1638
        test.run(unittest.TestResult())
 
1639
        self.assertEqual('original', obj.test_attr)
 
1640
 
 
1641
    def test_overrideAttr_with_value(self):
 
1642
        self.test_attr = 'original' # Define a test attribute
 
1643
        obj = self # Make 'obj' visible to the embedded test
 
1644
        class Test(tests.TestCase):
 
1645
 
 
1646
            def setUp(self):
 
1647
                tests.TestCase.setUp(self)
 
1648
                self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
 
1649
 
 
1650
            def test_value(self):
 
1651
                self.assertEqual('original', self.orig)
 
1652
                self.assertEqual('modified', obj.test_attr)
 
1653
 
 
1654
        test = Test('test_value')
 
1655
        test.run(unittest.TestResult())
 
1656
        self.assertEqual('original', obj.test_attr)
 
1657
 
1638
1658
 
1639
1659
# NB: Don't delete this; it's not actually from 0.11!
1640
1660
@deprecated_function(deprecated_in((0, 11, 0)))
1784
1804
        # make_branch_and_tree has to use local branch and repositories
1785
1805
        # when the vfs transport and local disk are colocated, even if
1786
1806
        # a different transport is in use for url generation.
1787
 
        from bzrlib.transport.fakevfat import FakeVFATServer
1788
 
        self.transport_server = FakeVFATServer
 
1807
        self.transport_server = test_server.FakeVFATServer
1789
1808
        self.assertFalse(self.get_url('t1').startswith('file://'))
1790
1809
        tree = self.make_branch_and_tree('t1')
1791
1810
        base = tree.bzrdir.root_transport.base
1931
1950
        self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1932
1951
 
1933
1952
    def test_transport_memory(self):
1934
 
        self.check_transport_set(bzrlib.transport.memory.MemoryServer)
 
1953
        self.check_transport_set(memory.MemoryServer)
1935
1954
 
1936
1955
 
1937
1956
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
2380
2399
 
2381
2400
 
2382
2401
simple_thunk_feature = tests._CompatabilityThunkFeature(
2383
 
    'bzrlib.tests', 'UnicodeFilename',
2384
 
    'bzrlib.tests.test_selftest.simple_thunk_feature',
2385
 
    deprecated_in((2,1,0)))
 
2402
    deprecated_in((2, 1, 0)),
 
2403
    'bzrlib.tests.test_selftest',
 
2404
    'simple_thunk_feature','UnicodeFilename',
 
2405
    replacement_module='bzrlib.tests'
 
2406
    )
2386
2407
 
2387
2408
class Test_CompatibilityFeature(tests.TestCase):
2388
2409
 
2393
2414
            simple_thunk_feature.available)
2394
2415
        self.assertEqual(tests.UnicodeFilename.available(), res)
2395
2416
 
2396
 
        
 
2417
 
2397
2418
class TestModuleAvailableFeature(tests.TestCase):
2398
2419
 
2399
2420
    def test_available_module(self):
2600
2621
        # Running bzr in blackbox mode, normal/expected/user errors should be
2601
2622
        # caught in the regular way and turned into an error message plus exit
2602
2623
        # code.
2603
 
        transport_server = MemoryServer()
 
2624
        transport_server = memory.MemoryServer()
2604
2625
        transport_server.start_server()
2605
2626
        self.addCleanup(transport_server.stop_server)
2606
2627
        url = transport_server.get_url()
2764
2785
        # test doubles that supply a few sample tests to load, and check they
2765
2786
        # are loaded.
2766
2787
        calls = []
2767
 
        def _test_suite_testmod_names():
 
2788
        def testmod_names():
2768
2789
            calls.append("testmod_names")
2769
2790
            return [
2770
2791
                'bzrlib.tests.blackbox.test_branch',
2771
2792
                'bzrlib.tests.per_transport',
2772
2793
                'bzrlib.tests.test_selftest',
2773
2794
                ]
2774
 
        original_testmod_names = tests._test_suite_testmod_names
2775
 
        def _test_suite_modules_to_doctest():
 
2795
        self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
 
2796
        def doctests():
2776
2797
            calls.append("modules_to_doctest")
2777
2798
            return ['bzrlib.timestamp']
2778
 
        orig_modules_to_doctest = tests._test_suite_modules_to_doctest
2779
 
        def restore_names():
2780
 
            tests._test_suite_testmod_names = original_testmod_names
2781
 
            tests._test_suite_modules_to_doctest = orig_modules_to_doctest
2782
 
        self.addCleanup(restore_names)
2783
 
        tests._test_suite_testmod_names = _test_suite_testmod_names
2784
 
        tests._test_suite_modules_to_doctest = _test_suite_modules_to_doctest
 
2799
        self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2785
2800
        expected_test_list = [
2786
2801
            # testmod_names
2787
2802
            'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',