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))
616
614
# When _lock_check_thorough is disabled, then we don't trigger a
618
self.assertLength(0, total_failures)
616
self.assertEqual(0, len(result.errors))
621
619
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
622
620
"""Tests for the convenience functions TestCaseWithTransport introduces."""
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
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'))
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'))
677
679
super(TestTestCaseTransports, self).setUp()
678
self.vfs_transport_factory = memory.MemoryServer
680
self.vfs_transport_factory = MemoryServer
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)
685
687
# should not be on disk, should only be in memory
686
688
self.failIfExists('subdir')
689
691
class TestChrootedTest(tests.ChrootedTestCase):
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())
694
697
self.assertEqual(url, t.clone('..').base)
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
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)
1950
1953
def test_transport_memory(self):
1951
self.check_transport_set(memory.MemoryServer)
1954
self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1954
1957
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
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'
2403
'bzrlib.tests', 'UnicodeFilename',
2404
'bzrlib.tests.test_selftest.simple_thunk_feature',
2405
deprecated_in((2,1,0)))
2406
2407
class Test_CompatibilityFeature(tests.TestCase):
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
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()
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
2813
if __doc__ is not None:
2814
expected_test_list.extend([
2815
# modules_to_doctest
2816
'bzrlib.timestamp.format_highres_date',
2818
2810
suite = tests.test_suite()
2819
2811
self.assertEqual(set(["testmod_names", "modules_to_doctest"]),