122
122
self.failUnlessExists(filename)
125
class TestClassesAvailable(tests.TestCase):
126
"""As a convenience we expose Test* classes from bzrlib.tests"""
128
def test_test_case(self):
129
from bzrlib.tests import TestCase
131
def test_test_loader(self):
132
from bzrlib.tests import TestLoader
134
def test_test_suite(self):
135
from bzrlib.tests import TestSuite
138
125
class TestTransportScenarios(tests.TestCase):
139
126
"""A group of tests that test the transport implementation adaption core.
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))
629
615
# When _lock_check_thorough is disabled, then we don't trigger a
631
self.assertLength(0, total_failures)
617
self.assertEqual(0, len(result.errors))
634
620
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
635
621
"""Tests for the convenience functions TestCaseWithTransport introduces."""
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
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'))
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'))
690
680
super(TestTestCaseTransports, self).setUp()
691
self.vfs_transport_factory = memory.MemoryServer
681
self.vfs_transport_factory = MemoryServer
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)
698
688
# should not be on disk, should only be in memory
699
689
self.failIfExists('subdir')
702
692
class TestChrootedTest(tests.ChrootedTestCase):
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())
707
698
self.assertEqual(url, t.clone('..').base)
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))
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
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)
1966
1954
def test_transport_memory(self):
1967
self.check_transport_set(memory.MemoryServer)
1955
self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1970
1958
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
2353
2341
os.chdir = orig_chdir
2354
2342
self.assertEqual(['foo', 'current'], chdirs)
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")
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
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()
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
2834
if __doc__ is not None:
2835
expected_test_list.extend([
2836
# modules_to_doctest
2837
'bzrlib.timestamp.format_highres_date',
2839
2813
suite = tests.test_suite()
2840
2814
self.assertEqual(set(["testmod_names", "modules_to_doctest"]),