~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Martin Pool
  • Date: 2010-01-29 14:09:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129140905-2uiarb6p8di1ywsr
Correction to url

from review: https://code.edge.launchpad.net/~mbp/bzr/doc/+merge/18250

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
63
63
from bzrlib.tests import (
64
64
    features,
65
65
    test_lsprof,
66
 
    test_server,
67
66
    test_sftp_transport,
68
67
    TestUtil,
69
68
    )
70
69
from bzrlib.trace import note
71
 
from bzrlib.transport import memory
 
70
from bzrlib.transport.memory import MemoryServer, MemoryTransport
72
71
from bzrlib.version import _get_bzr_source_tree
73
72
 
74
73
 
609
608
                l.attempt_lock()
610
609
        test = TestDanglingLock('test_function')
611
610
        result = test.run()
612
 
        total_failures = result.errors + result.failures
613
611
        if self._lock_check_thorough:
614
 
            self.assertLength(1, total_failures)
 
612
            self.assertEqual(1, len(result.errors))
615
613
        else:
616
614
            # When _lock_check_thorough is disabled, then we don't trigger a
617
615
            # failure
618
 
            self.assertLength(0, total_failures)
 
616
            self.assertEqual(0, len(result.errors))
619
617
 
620
618
 
621
619
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
622
620
    """Tests for the convenience functions TestCaseWithTransport introduces."""
623
621
 
624
622
    def test_get_readonly_url_none(self):
 
623
        from bzrlib.transport import get_transport
 
624
        from bzrlib.transport.memory import MemoryServer
625
625
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
626
 
        self.vfs_transport_factory = memory.MemoryServer
 
626
        self.vfs_transport_factory = MemoryServer
627
627
        self.transport_readonly_server = None
628
628
        # calling get_readonly_transport() constructs a decorator on the url
629
629
        # for the server
630
630
        url = self.get_readonly_url()
631
631
        url2 = self.get_readonly_url('foo/bar')
632
 
        t = transport.get_transport(url)
633
 
        t2 = transport.get_transport(url2)
 
632
        t = get_transport(url)
 
633
        t2 = get_transport(url2)
634
634
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
635
635
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
636
636
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
637
637
 
638
638
    def test_get_readonly_url_http(self):
639
639
        from bzrlib.tests.http_server import HttpServer
 
640
        from bzrlib.transport import get_transport
 
641
        from bzrlib.transport.local import LocalURLServer
640
642
        from bzrlib.transport.http import HttpTransportBase
641
 
        self.transport_server = test_server.LocalURLServer
 
643
        self.transport_server = LocalURLServer
642
644
        self.transport_readonly_server = HttpServer
643
645
        # calling get_readonly_transport() gives us a HTTP server instance.
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'))
675
677
 
676
678
    def setUp(self):
677
679
        super(TestTestCaseTransports, self).setUp()
678
 
        self.vfs_transport_factory = memory.MemoryServer
 
680
        self.vfs_transport_factory = MemoryServer
679
681
 
680
682
    def test_make_bzrdir_preserves_transport(self):
681
683
        t = self.get_transport()
682
684
        result_bzrdir = self.make_bzrdir('subdir')
683
685
        self.assertIsInstance(result_bzrdir.transport,
684
 
                              memory.MemoryTransport)
 
686
                              MemoryTransport)
685
687
        # should not be on disk, should only be in memory
686
688
        self.failIfExists('subdir')
687
689
 
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
 
1466
1469
        # permitted.
1467
1470
        # Manually set one up (TestCase doesn't and shouldn't provide magic
1468
1471
        # machinery)
1469
 
        transport_server = memory.MemoryServer()
 
1472
        transport_server = MemoryServer()
1470
1473
        transport_server.start_server()
1471
1474
        self.addCleanup(transport_server.stop_server)
1472
1475
        t = transport.get_transport(transport_server.get_url())
1554
1557
            result.calls)
1555
1558
 
1556
1559
    def test_start_server_registers_url(self):
1557
 
        transport_server = memory.MemoryServer()
 
1560
        transport_server = MemoryServer()
1558
1561
        # A little strict, but unlikely to be changed soon.
1559
1562
        self.assertEqual([], self._bzr_selftest_roots)
1560
1563
        self.start_server(transport_server)
1801
1804
        # make_branch_and_tree has to use local branch and repositories
1802
1805
        # when the vfs transport and local disk are colocated, even if
1803
1806
        # a different transport is in use for url generation.
1804
 
        self.transport_server = test_server.FakeVFATServer
 
1807
        from bzrlib.transport.fakevfat import FakeVFATServer
 
1808
        self.transport_server = FakeVFATServer
1805
1809
        self.assertFalse(self.get_url('t1').startswith('file://'))
1806
1810
        tree = self.make_branch_and_tree('t1')
1807
1811
        base = tree.bzrdir.root_transport.base
1944
1948
 
1945
1949
    def test_transport_sftp(self):
1946
1950
        self.requireFeature(features.paramiko)
1947
 
        from bzrlib.tests import stub_sftp
1948
 
        self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
 
1951
        self.check_transport_set(bzrlib.transport.sftp.SFTPAbsoluteServer)
1949
1952
 
1950
1953
    def test_transport_memory(self):
1951
 
        self.check_transport_set(memory.MemoryServer)
 
1954
        self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1952
1955
 
1953
1956
 
1954
1957
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
2397
2400
 
2398
2401
 
2399
2402
simple_thunk_feature = tests._CompatabilityThunkFeature(
2400
 
    deprecated_in((2, 1, 0)),
2401
 
    'bzrlib.tests.test_selftest',
2402
 
    'simple_thunk_feature','UnicodeFilename',
2403
 
    replacement_module='bzrlib.tests'
2404
 
    )
 
2403
    'bzrlib.tests', 'UnicodeFilename',
 
2404
    'bzrlib.tests.test_selftest.simple_thunk_feature',
 
2405
    deprecated_in((2,1,0)))
2405
2406
 
2406
2407
class Test_CompatibilityFeature(tests.TestCase):
2407
2408
 
2412
2413
            simple_thunk_feature.available)
2413
2414
        self.assertEqual(tests.UnicodeFilename.available(), res)
2414
2415
 
2415
 
 
 
2416
        
2416
2417
class TestModuleAvailableFeature(tests.TestCase):
2417
2418
 
2418
2419
    def test_available_module(self):
2619
2620
        # Running bzr in blackbox mode, normal/expected/user errors should be
2620
2621
        # caught in the regular way and turned into an error message plus exit
2621
2622
        # code.
2622
 
        transport_server = memory.MemoryServer()
 
2623
        transport_server = MemoryServer()
2623
2624
        transport_server.start_server()
2624
2625
        self.addCleanup(transport_server.stop_server)
2625
2626
        url = transport_server.get_url()
2771
2772
        # Test that a plausible list of modules to doctest is returned
2772
2773
        # by _test_suite_modules_to_doctest.
2773
2774
        test_list = tests._test_suite_modules_to_doctest()
2774
 
        if __doc__ is None:
2775
 
            # When docstrings are stripped, there are no modules to doctest
2776
 
            self.assertEqual([], test_list)
2777
 
            return
2778
2775
        self.assertSubset([
2779
2776
            'bzrlib.timestamp',
2780
2777
            ],
2797
2794
        self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2798
2795
        def doctests():
2799
2796
            calls.append("modules_to_doctest")
2800
 
            if __doc__ is None:
2801
 
                return []
2802
2797
            return ['bzrlib.timestamp']
2803
2798
        self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2804
2799
        expected_test_list = [
2807
2802
            ('bzrlib.tests.per_transport.TransportTests'
2808
2803
             '.test_abspath(LocalTransport,LocalURLServer)'),
2809
2804
            'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
 
2805
            # modules_to_doctest
 
2806
            'bzrlib.timestamp.format_highres_date',
2810
2807
            # plugins can't be tested that way since selftest may be run with
2811
2808
            # --no-plugins
2812
2809
            ]
2813
 
        if __doc__ is not None:
2814
 
            expected_test_list.extend([
2815
 
                # modules_to_doctest
2816
 
                'bzrlib.timestamp.format_highres_date',
2817
 
                ])
2818
2810
        suite = tests.test_suite()
2819
2811
        self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
2820
2812
            set(calls))