~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: 2010-02-11 02:16:42 UTC
  • mfrom: (5017.1.2 initialize)
  • Revision ID: pqm@pqm.ubuntu.com-20100211021642-eitum30b2e09oalf
(mbp) Add bzrlib.initialize

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    )
63
63
from bzrlib.tests import (
64
64
    features,
 
65
    stub_sftp,
65
66
    test_lsprof,
66
 
    test_server,
67
67
    test_sftp_transport,
68
68
    TestUtil,
69
69
    )
70
70
from bzrlib.trace import note
71
 
from bzrlib.transport import memory
 
71
from bzrlib.transport.memory import MemoryServer, MemoryTransport
72
72
from bzrlib.version import _get_bzr_source_tree
73
73
 
74
74
 
122
122
        self.failUnlessExists(filename)
123
123
 
124
124
 
125
 
class TestClassesAvailable(tests.TestCase):
126
 
    """As a convenience we expose Test* classes from bzrlib.tests"""
127
 
 
128
 
    def test_test_case(self):
129
 
        from bzrlib.tests import TestCase
130
 
 
131
 
    def test_test_loader(self):
132
 
        from bzrlib.tests import TestLoader
133
 
 
134
 
    def test_test_suite(self):
135
 
        from bzrlib.tests import TestSuite
136
 
 
137
 
 
138
125
class TestTransportScenarios(tests.TestCase):
139
126
    """A group of tests that test the transport implementation adaption core.
140
127
 
221
208
    def test_scenarios(self):
222
209
        # check that constructor parameters are passed through to the adapted
223
210
        # test.
224
 
        from bzrlib.tests.per_controldir import make_scenarios
 
211
        from bzrlib.tests.per_bzrdir import make_scenarios
225
212
        vfs_factory = "v"
226
213
        server1 = "a"
227
214
        server2 = "b"
622
609
                l.attempt_lock()
623
610
        test = TestDanglingLock('test_function')
624
611
        result = test.run()
625
 
        total_failures = result.errors + result.failures
626
612
        if self._lock_check_thorough:
627
 
            self.assertLength(1, total_failures)
 
613
            self.assertEqual(1, len(result.errors))
628
614
        else:
629
615
            # When _lock_check_thorough is disabled, then we don't trigger a
630
616
            # failure
631
 
            self.assertLength(0, total_failures)
 
617
            self.assertEqual(0, len(result.errors))
632
618
 
633
619
 
634
620
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
635
621
    """Tests for the convenience functions TestCaseWithTransport introduces."""
636
622
 
637
623
    def test_get_readonly_url_none(self):
 
624
        from bzrlib.transport import get_transport
 
625
        from bzrlib.transport.memory import MemoryServer
638
626
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
639
 
        self.vfs_transport_factory = memory.MemoryServer
 
627
        self.vfs_transport_factory = MemoryServer
640
628
        self.transport_readonly_server = None
641
629
        # calling get_readonly_transport() constructs a decorator on the url
642
630
        # for the server
643
631
        url = self.get_readonly_url()
644
632
        url2 = self.get_readonly_url('foo/bar')
645
 
        t = transport.get_transport(url)
646
 
        t2 = transport.get_transport(url2)
 
633
        t = get_transport(url)
 
634
        t2 = get_transport(url2)
647
635
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
648
636
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
649
637
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
650
638
 
651
639
    def test_get_readonly_url_http(self):
652
640
        from bzrlib.tests.http_server import HttpServer
 
641
        from bzrlib.transport import get_transport
 
642
        from bzrlib.transport.local import LocalURLServer
653
643
        from bzrlib.transport.http import HttpTransportBase
654
 
        self.transport_server = test_server.LocalURLServer
 
644
        self.transport_server = LocalURLServer
655
645
        self.transport_readonly_server = HttpServer
656
646
        # calling get_readonly_transport() gives us a HTTP server instance.
657
647
        url = self.get_readonly_url()
658
648
        url2 = self.get_readonly_url('foo/bar')
659
649
        # the transport returned may be any HttpTransportBase subclass
660
 
        t = transport.get_transport(url)
661
 
        t2 = transport.get_transport(url2)
 
650
        t = get_transport(url)
 
651
        t2 = get_transport(url2)
662
652
        self.failUnless(isinstance(t, HttpTransportBase))
663
653
        self.failUnless(isinstance(t2, HttpTransportBase))
664
654
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
688
678
 
689
679
    def setUp(self):
690
680
        super(TestTestCaseTransports, self).setUp()
691
 
        self.vfs_transport_factory = memory.MemoryServer
 
681
        self.vfs_transport_factory = MemoryServer
692
682
 
693
683
    def test_make_bzrdir_preserves_transport(self):
694
684
        t = self.get_transport()
695
685
        result_bzrdir = self.make_bzrdir('subdir')
696
686
        self.assertIsInstance(result_bzrdir.transport,
697
 
                              memory.MemoryTransport)
 
687
                              MemoryTransport)
698
688
        # should not be on disk, should only be in memory
699
689
        self.failIfExists('subdir')
700
690
 
702
692
class TestChrootedTest(tests.ChrootedTestCase):
703
693
 
704
694
    def test_root_is_root(self):
705
 
        t = transport.get_transport(self.get_readonly_url())
 
695
        from bzrlib.transport import get_transport
 
696
        t = get_transport(self.get_readonly_url())
706
697
        url = t.base
707
698
        self.assertEqual(url, t.clone('..').base)
708
699
 
814
805
        self.requireFeature(test_lsprof.LSProfFeature)
815
806
        result_stream = StringIO()
816
807
        result = bzrlib.tests.VerboseTestResult(
817
 
            result_stream,
 
808
            unittest._WritelnDecorator(result_stream),
818
809
            descriptions=0,
819
810
            verbosity=2,
820
811
            )
875
866
        # verbose test output formatting
876
867
        result_stream = StringIO()
877
868
        result = bzrlib.tests.VerboseTestResult(
878
 
            result_stream,
 
869
            unittest._WritelnDecorator(result_stream),
879
870
            descriptions=0,
880
871
            verbosity=2,
881
872
            )
891
882
        output = result_stream.getvalue()[prefix:]
892
883
        lines = output.splitlines()
893
884
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
894
 
        if sys.version_info > (2, 7):
895
 
            self.expectFailure("_ExpectedFailure on 2.7 loses the message",
896
 
                self.assertNotEqual, lines[1], '    ')
897
885
        self.assertEqual(lines[1], '    foo')
898
886
        self.assertEqual(2, len(lines))
899
887
 
933
921
        # verbose test output formatting
934
922
        result_stream = StringIO()
935
923
        result = bzrlib.tests.VerboseTestResult(
936
 
            result_stream,
 
924
            unittest._WritelnDecorator(result_stream),
937
925
            descriptions=0,
938
926
            verbosity=2,
939
927
            )
1435
1423
        sample_test = TestTestCase("method_that_times_a_bit_twice")
1436
1424
        output_stream = StringIO()
1437
1425
        result = bzrlib.tests.VerboseTestResult(
1438
 
            output_stream,
 
1426
            unittest._WritelnDecorator(output_stream),
1439
1427
            descriptions=0,
1440
1428
            verbosity=2)
1441
1429
        sample_test.run(result)
1482
1470
        # permitted.
1483
1471
        # Manually set one up (TestCase doesn't and shouldn't provide magic
1484
1472
        # machinery)
1485
 
        transport_server = memory.MemoryServer()
 
1473
        transport_server = MemoryServer()
1486
1474
        transport_server.start_server()
1487
1475
        self.addCleanup(transport_server.stop_server)
1488
1476
        t = transport.get_transport(transport_server.get_url())
1570
1558
            result.calls)
1571
1559
 
1572
1560
    def test_start_server_registers_url(self):
1573
 
        transport_server = memory.MemoryServer()
 
1561
        transport_server = MemoryServer()
1574
1562
        # A little strict, but unlikely to be changed soon.
1575
1563
        self.assertEqual([], self._bzr_selftest_roots)
1576
1564
        self.start_server(transport_server)
1817
1805
        # make_branch_and_tree has to use local branch and repositories
1818
1806
        # when the vfs transport and local disk are colocated, even if
1819
1807
        # a different transport is in use for url generation.
1820
 
        self.transport_server = test_server.FakeVFATServer
 
1808
        from bzrlib.transport.fakevfat import FakeVFATServer
 
1809
        self.transport_server = FakeVFATServer
1821
1810
        self.assertFalse(self.get_url('t1').startswith('file://'))
1822
1811
        tree = self.make_branch_and_tree('t1')
1823
1812
        base = tree.bzrdir.root_transport.base
1960
1949
 
1961
1950
    def test_transport_sftp(self):
1962
1951
        self.requireFeature(features.paramiko)
1963
 
        from bzrlib.tests import stub_sftp
1964
1952
        self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1965
1953
 
1966
1954
    def test_transport_memory(self):
1967
 
        self.check_transport_set(memory.MemoryServer)
 
1955
        self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1968
1956
 
1969
1957
 
1970
1958
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
2353
2341
            os.chdir = orig_chdir
2354
2342
        self.assertEqual(['foo', 'current'], chdirs)
2355
2343
 
2356
 
    def test_get_bzr_path_with_cwd_bzrlib(self):
2357
 
        self.get_source_path = lambda: ""
2358
 
        self.overrideAttr(os.path, "isfile", lambda path: True)
2359
 
        self.assertEqual(self.get_bzr_path(), "bzr")
2360
 
 
2361
2344
 
2362
2345
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2363
2346
    """Tests that really need to do things with an external bzr."""
2640
2623
        # Running bzr in blackbox mode, normal/expected/user errors should be
2641
2624
        # caught in the regular way and turned into an error message plus exit
2642
2625
        # code.
2643
 
        transport_server = memory.MemoryServer()
 
2626
        transport_server = MemoryServer()
2644
2627
        transport_server.start_server()
2645
2628
        self.addCleanup(transport_server.stop_server)
2646
2629
        url = transport_server.get_url()
2792
2775
        # Test that a plausible list of modules to doctest is returned
2793
2776
        # by _test_suite_modules_to_doctest.
2794
2777
        test_list = tests._test_suite_modules_to_doctest()
2795
 
        if __doc__ is None:
2796
 
            # When docstrings are stripped, there are no modules to doctest
2797
 
            self.assertEqual([], test_list)
2798
 
            return
2799
2778
        self.assertSubset([
2800
2779
            'bzrlib.timestamp',
2801
2780
            ],
2818
2797
        self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2819
2798
        def doctests():
2820
2799
            calls.append("modules_to_doctest")
2821
 
            if __doc__ is None:
2822
 
                return []
2823
2800
            return ['bzrlib.timestamp']
2824
2801
        self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2825
2802
        expected_test_list = [
2828
2805
            ('bzrlib.tests.per_transport.TransportTests'
2829
2806
             '.test_abspath(LocalTransport,LocalURLServer)'),
2830
2807
            'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
 
2808
            # modules_to_doctest
 
2809
            'bzrlib.timestamp.format_highres_date',
2831
2810
            # plugins can't be tested that way since selftest may be run with
2832
2811
            # --no-plugins
2833
2812
            ]
2834
 
        if __doc__ is not None:
2835
 
            expected_test_list.extend([
2836
 
                # modules_to_doctest
2837
 
                'bzrlib.timestamp.format_highres_date',
2838
 
                ])
2839
2813
        suite = tests.test_suite()
2840
2814
        self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
2841
2815
            set(calls))