~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-10 09:22:04 UTC
  • mto: This revision was merged to the branch mainline in revision 5142.
  • Revision ID: robertc@robertcollins.net-20100410092204-jrdwwf7vtfr0t41k
``bzrlib.mutabletree.MutableTree.commit`` will now support a passed in
config as in previous versions of bzrlib. (Robert Collins)

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
67
    test_server,
67
68
    test_sftp_transport,
208
209
    def test_scenarios(self):
209
210
        # check that constructor parameters are passed through to the adapted
210
211
        # test.
211
 
        from bzrlib.tests.per_controldir import make_scenarios
 
212
        from bzrlib.tests.per_bzrdir import make_scenarios
212
213
        vfs_factory = "v"
213
214
        server1 = "a"
214
215
        server2 = "b"
609
610
                l.attempt_lock()
610
611
        test = TestDanglingLock('test_function')
611
612
        result = test.run()
612
 
        total_failures = result.errors + result.failures
613
613
        if self._lock_check_thorough:
614
 
            self.assertLength(1, total_failures)
 
614
            self.assertEqual(1, len(result.errors))
615
615
        else:
616
616
            # When _lock_check_thorough is disabled, then we don't trigger a
617
617
            # failure
618
 
            self.assertLength(0, total_failures)
 
618
            self.assertEqual(0, len(result.errors))
619
619
 
620
620
 
621
621
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
622
622
    """Tests for the convenience functions TestCaseWithTransport introduces."""
623
623
 
624
624
    def test_get_readonly_url_none(self):
 
625
        from bzrlib.transport import get_transport
625
626
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
626
627
        self.vfs_transport_factory = memory.MemoryServer
627
628
        self.transport_readonly_server = None
629
630
        # for the server
630
631
        url = self.get_readonly_url()
631
632
        url2 = self.get_readonly_url('foo/bar')
632
 
        t = transport.get_transport(url)
633
 
        t2 = transport.get_transport(url2)
 
633
        t = get_transport(url)
 
634
        t2 = get_transport(url2)
634
635
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
635
636
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
636
637
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
637
638
 
638
639
    def test_get_readonly_url_http(self):
639
640
        from bzrlib.tests.http_server import HttpServer
 
641
        from bzrlib.transport import get_transport
640
642
        from bzrlib.transport.http import HttpTransportBase
641
643
        self.transport_server = test_server.LocalURLServer
642
644
        self.transport_readonly_server = HttpServer
644
646
        url = self.get_readonly_url()
645
647
        url2 = self.get_readonly_url('foo/bar')
646
648
        # the transport returned may be any HttpTransportBase subclass
647
 
        t = transport.get_transport(url)
648
 
        t2 = transport.get_transport(url2)
 
649
        t = get_transport(url)
 
650
        t2 = get_transport(url2)
649
651
        self.failUnless(isinstance(t, HttpTransportBase))
650
652
        self.failUnless(isinstance(t2, HttpTransportBase))
651
653
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
689
691
class TestChrootedTest(tests.ChrootedTestCase):
690
692
 
691
693
    def test_root_is_root(self):
692
 
        t = transport.get_transport(self.get_readonly_url())
 
694
        from bzrlib.transport import get_transport
 
695
        t = get_transport(self.get_readonly_url())
693
696
        url = t.base
694
697
        self.assertEqual(url, t.clone('..').base)
695
698
 
801
804
        self.requireFeature(test_lsprof.LSProfFeature)
802
805
        result_stream = StringIO()
803
806
        result = bzrlib.tests.VerboseTestResult(
804
 
            result_stream,
 
807
            unittest._WritelnDecorator(result_stream),
805
808
            descriptions=0,
806
809
            verbosity=2,
807
810
            )
862
865
        # verbose test output formatting
863
866
        result_stream = StringIO()
864
867
        result = bzrlib.tests.VerboseTestResult(
865
 
            result_stream,
 
868
            unittest._WritelnDecorator(result_stream),
866
869
            descriptions=0,
867
870
            verbosity=2,
868
871
            )
878
881
        output = result_stream.getvalue()[prefix:]
879
882
        lines = output.splitlines()
880
883
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
881
 
        if sys.version_info > (2, 7):
882
 
            self.expectFailure("_ExpectedFailure on 2.7 loses the message",
883
 
                self.assertNotEqual, lines[1], '    ')
884
884
        self.assertEqual(lines[1], '    foo')
885
885
        self.assertEqual(2, len(lines))
886
886
 
920
920
        # verbose test output formatting
921
921
        result_stream = StringIO()
922
922
        result = bzrlib.tests.VerboseTestResult(
923
 
            result_stream,
 
923
            unittest._WritelnDecorator(result_stream),
924
924
            descriptions=0,
925
925
            verbosity=2,
926
926
            )
1422
1422
        sample_test = TestTestCase("method_that_times_a_bit_twice")
1423
1423
        output_stream = StringIO()
1424
1424
        result = bzrlib.tests.VerboseTestResult(
1425
 
            output_stream,
 
1425
            unittest._WritelnDecorator(output_stream),
1426
1426
            descriptions=0,
1427
1427
            verbosity=2)
1428
1428
        sample_test.run(result)
1947
1947
 
1948
1948
    def test_transport_sftp(self):
1949
1949
        self.requireFeature(features.paramiko)
1950
 
        from bzrlib.tests import stub_sftp
1951
1950
        self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1952
1951
 
1953
1952
    def test_transport_memory(self):
2340
2339
            os.chdir = orig_chdir
2341
2340
        self.assertEqual(['foo', 'current'], chdirs)
2342
2341
 
2343
 
    def test_get_bzr_path_with_cwd_bzrlib(self):
2344
 
        self.get_source_path = lambda: ""
2345
 
        self.overrideAttr(os.path, "isfile", lambda path: True)
2346
 
        self.assertEqual(self.get_bzr_path(), "bzr")
2347
 
 
2348
2342
 
2349
2343
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2350
2344
    """Tests that really need to do things with an external bzr."""
2779
2773
        # Test that a plausible list of modules to doctest is returned
2780
2774
        # by _test_suite_modules_to_doctest.
2781
2775
        test_list = tests._test_suite_modules_to_doctest()
2782
 
        if __doc__ is None:
2783
 
            # When docstrings are stripped, there are no modules to doctest
2784
 
            self.assertEqual([], test_list)
2785
 
            return
2786
2776
        self.assertSubset([
2787
2777
            'bzrlib.timestamp',
2788
2778
            ],
2805
2795
        self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2806
2796
        def doctests():
2807
2797
            calls.append("modules_to_doctest")
2808
 
            if __doc__ is None:
2809
 
                return []
2810
2798
            return ['bzrlib.timestamp']
2811
2799
        self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2812
2800
        expected_test_list = [
2815
2803
            ('bzrlib.tests.per_transport.TransportTests'
2816
2804
             '.test_abspath(LocalTransport,LocalURLServer)'),
2817
2805
            'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
 
2806
            # modules_to_doctest
 
2807
            'bzrlib.timestamp.format_highres_date',
2818
2808
            # plugins can't be tested that way since selftest may be run with
2819
2809
            # --no-plugins
2820
2810
            ]
2821
 
        if __doc__ is not None:
2822
 
            expected_test_list.extend([
2823
 
                # modules_to_doctest
2824
 
                'bzrlib.timestamp.format_highres_date',
2825
 
                ])
2826
2811
        suite = tests.test_suite()
2827
2812
        self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
2828
2813
            set(calls))