~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: 2010-08-04 04:33:24 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100804043324-1ldc2v2w1kza7ox4
get into the nitty gritty for the _key_to_sha1 function.

It doesn't seem to help to op-out of the actual unhexlify call, so at least
that doesn't seem to be the performance overhead.
We get down to around 19.9us for _key_to_sha1 across 120 keys, which is
0.166us per key.

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,
66
65
    test_lsprof,
67
66
    test_server,
68
67
    test_sftp_transport,
610
609
                l.attempt_lock()
611
610
        test = TestDanglingLock('test_function')
612
611
        result = test.run()
 
612
        total_failures = result.errors + result.failures
613
613
        if self._lock_check_thorough:
614
 
            self.assertEqual(1, len(result.errors))
 
614
            self.assertLength(1, total_failures)
615
615
        else:
616
616
            # When _lock_check_thorough is disabled, then we don't trigger a
617
617
            # failure
618
 
            self.assertEqual(0, len(result.errors))
 
618
            self.assertLength(0, total_failures)
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
626
625
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
627
626
        self.vfs_transport_factory = memory.MemoryServer
628
627
        self.transport_readonly_server = None
630
629
        # for the server
631
630
        url = self.get_readonly_url()
632
631
        url2 = self.get_readonly_url('foo/bar')
633
 
        t = get_transport(url)
634
 
        t2 = get_transport(url2)
 
632
        t = transport.get_transport(url)
 
633
        t2 = transport.get_transport(url2)
635
634
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
636
635
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
637
636
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
638
637
 
639
638
    def test_get_readonly_url_http(self):
640
639
        from bzrlib.tests.http_server import HttpServer
641
 
        from bzrlib.transport import get_transport
642
640
        from bzrlib.transport.http import HttpTransportBase
643
641
        self.transport_server = test_server.LocalURLServer
644
642
        self.transport_readonly_server = HttpServer
646
644
        url = self.get_readonly_url()
647
645
        url2 = self.get_readonly_url('foo/bar')
648
646
        # the transport returned may be any HttpTransportBase subclass
649
 
        t = get_transport(url)
650
 
        t2 = get_transport(url2)
 
647
        t = transport.get_transport(url)
 
648
        t2 = transport.get_transport(url2)
651
649
        self.failUnless(isinstance(t, HttpTransportBase))
652
650
        self.failUnless(isinstance(t2, HttpTransportBase))
653
651
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
691
689
class TestChrootedTest(tests.ChrootedTestCase):
692
690
 
693
691
    def test_root_is_root(self):
694
 
        from bzrlib.transport import get_transport
695
 
        t = get_transport(self.get_readonly_url())
 
692
        t = transport.get_transport(self.get_readonly_url())
696
693
        url = t.base
697
694
        self.assertEqual(url, t.clone('..').base)
698
695
 
1947
1944
 
1948
1945
    def test_transport_sftp(self):
1949
1946
        self.requireFeature(features.paramiko)
 
1947
        from bzrlib.tests import stub_sftp
1950
1948
        self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1951
1949
 
1952
1950
    def test_transport_memory(self):
2339
2337
            os.chdir = orig_chdir
2340
2338
        self.assertEqual(['foo', 'current'], chdirs)
2341
2339
 
 
2340
    def test_get_bzr_path_with_cwd_bzrlib(self):
 
2341
        self.get_source_path = lambda: ""
 
2342
        self.overrideAttr(os.path, "isfile", lambda path: True)
 
2343
        self.assertEqual(self.get_bzr_path(), "bzr")
 
2344
 
2342
2345
 
2343
2346
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2344
2347
    """Tests that really need to do things with an external bzr."""
2773
2776
        # Test that a plausible list of modules to doctest is returned
2774
2777
        # by _test_suite_modules_to_doctest.
2775
2778
        test_list = tests._test_suite_modules_to_doctest()
 
2779
        if __doc__ is None:
 
2780
            # When docstrings are stripped, there are no modules to doctest
 
2781
            self.assertEqual([], test_list)
 
2782
            return
2776
2783
        self.assertSubset([
2777
2784
            'bzrlib.timestamp',
2778
2785
            ],
2795
2802
        self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2796
2803
        def doctests():
2797
2804
            calls.append("modules_to_doctest")
 
2805
            if __doc__ is None:
 
2806
                return []
2798
2807
            return ['bzrlib.timestamp']
2799
2808
        self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2800
2809
        expected_test_list = [
2803
2812
            ('bzrlib.tests.per_transport.TransportTests'
2804
2813
             '.test_abspath(LocalTransport,LocalURLServer)'),
2805
2814
            'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
2806
 
            # modules_to_doctest
2807
 
            'bzrlib.timestamp.format_highres_date',
2808
2815
            # plugins can't be tested that way since selftest may be run with
2809
2816
            # --no-plugins
2810
2817
            ]
 
2818
        if __doc__ is not None:
 
2819
            expected_test_list.extend([
 
2820
                # modules_to_doctest
 
2821
                'bzrlib.timestamp.format_highres_date',
 
2822
                ])
2811
2823
        suite = tests.test_suite()
2812
2824
        self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
2813
2825
            set(calls))