610
610
test = TestDanglingLock('test_function')
611
611
result = test.run()
612
total_failures = result.errors + result.failures
613
612
if self._lock_check_thorough:
614
self.assertLength(1, total_failures)
613
self.assertEqual(1, len(result.errors))
616
615
# When _lock_check_thorough is disabled, then we don't trigger a
618
self.assertLength(0, total_failures)
617
self.assertEqual(0, len(result.errors))
621
620
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
622
621
"""Tests for the convenience functions TestCaseWithTransport introduces."""
624
623
def test_get_readonly_url_none(self):
624
from bzrlib.transport import get_transport
625
from bzrlib.transport.memory import MemoryServer
625
626
from bzrlib.transport.readonly import ReadonlyTransportDecorator
626
self.vfs_transport_factory = memory.MemoryServer
627
self.vfs_transport_factory = MemoryServer
627
628
self.transport_readonly_server = None
628
629
# calling get_readonly_transport() constructs a decorator on the url
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'))
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
642
from bzrlib.transport.local import LocalURLServer
640
643
from bzrlib.transport.http import HttpTransportBase
641
self.transport_server = test_server.LocalURLServer
644
self.transport_server = LocalURLServer
642
645
self.transport_readonly_server = HttpServer
643
646
# calling get_readonly_transport() gives us a HTTP server instance.
644
647
url = self.get_readonly_url()
645
648
url2 = self.get_readonly_url('foo/bar')
646
649
# the transport returned may be any HttpTransportBase subclass
647
t = transport.get_transport(url)
648
t2 = transport.get_transport(url2)
650
t = get_transport(url)
651
t2 = get_transport(url2)
649
652
self.failUnless(isinstance(t, HttpTransportBase))
650
653
self.failUnless(isinstance(t2, HttpTransportBase))
651
654
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
677
680
super(TestTestCaseTransports, self).setUp()
678
self.vfs_transport_factory = memory.MemoryServer
681
self.vfs_transport_factory = MemoryServer
680
683
def test_make_bzrdir_preserves_transport(self):
681
684
t = self.get_transport()
682
685
result_bzrdir = self.make_bzrdir('subdir')
683
686
self.assertIsInstance(result_bzrdir.transport,
684
memory.MemoryTransport)
685
688
# should not be on disk, should only be in memory
686
689
self.failIfExists('subdir')
689
692
class TestChrootedTest(tests.ChrootedTestCase):
691
694
def test_root_is_root(self):
692
t = transport.get_transport(self.get_readonly_url())
695
from bzrlib.transport import get_transport
696
t = get_transport(self.get_readonly_url())
694
698
self.assertEqual(url, t.clone('..').base)
751
755
def _patch_get_bzr_source_tree(self):
752
756
# Reading from the actual source tree breaks isolation, but we don't
753
757
# want to assume that thats *all* that would happen.
754
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
758
def _get_bzr_source_tree():
760
orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
761
bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
763
bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
764
self.addCleanup(restore)
756
766
def test_assigned_benchmark_file_stores_date(self):
757
767
self._patch_get_bzr_source_tree()
878
888
output = result_stream.getvalue()[prefix:]
879
889
lines = output.splitlines()
880
890
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
891
self.assertEqual(lines[1], ' foo')
885
892
self.assertEqual(2, len(lines))
1195
1202
# Reading from the actual source tree breaks isolation, but we don't
1196
1203
# want to assume that thats *all* that would happen.
1197
1204
self._get_source_tree_calls = []
1205
def _get_bzr_source_tree():
1199
1206
self._get_source_tree_calls.append("called")
1201
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
1208
orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
1209
bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
1211
bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
1212
self.addCleanup(restore)
1203
1214
def test_bench_history(self):
1204
1215
# tests that the running the benchmark passes bench_history into
1312
1323
self.assertEqual(flags, bzrlib.debug.debug_flags)
1314
1325
def change_selftest_debug_flags(self, new_flags):
1315
self.overrideAttr(tests, 'selftest_debug_flags', set(new_flags))
1326
orig_selftest_flags = tests.selftest_debug_flags
1327
self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1328
tests.selftest_debug_flags = set(new_flags)
1330
def _restore_selftest_debug_flags(self, flags):
1331
tests.selftest_debug_flags = flags
1317
1333
def test_allow_debug_flag(self):
1318
1334
"""The -Eallow_debug flag prevents bzrlib.debug.debug_flags from being
1559
1575
def test_start_server_registers_url(self):
1560
transport_server = memory.MemoryServer()
1576
transport_server = MemoryServer()
1561
1577
# A little strict, but unlikely to be changed soon.
1562
1578
self.assertEqual([], self._bzr_selftest_roots)
1563
1579
self.start_server(transport_server)
1619
1635
self.assertRaises(AssertionError,
1620
1636
self.assertListRaises, _TestException, success_generator)
1622
def test_overrideAttr_without_value(self):
1623
self.test_attr = 'original' # Define a test attribute
1624
obj = self # Make 'obj' visible to the embedded test
1625
class Test(tests.TestCase):
1628
tests.TestCase.setUp(self)
1629
self.orig = self.overrideAttr(obj, 'test_attr')
1631
def test_value(self):
1632
self.assertEqual('original', self.orig)
1633
self.assertEqual('original', obj.test_attr)
1634
obj.test_attr = 'modified'
1635
self.assertEqual('modified', obj.test_attr)
1637
test = Test('test_value')
1638
test.run(unittest.TestResult())
1639
self.assertEqual('original', obj.test_attr)
1641
def test_overrideAttr_with_value(self):
1642
self.test_attr = 'original' # Define a test attribute
1643
obj = self # Make 'obj' visible to the embedded test
1644
class Test(tests.TestCase):
1647
tests.TestCase.setUp(self)
1648
self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
1650
def test_value(self):
1651
self.assertEqual('original', self.orig)
1652
self.assertEqual('modified', obj.test_attr)
1654
test = Test('test_value')
1655
test.run(unittest.TestResult())
1656
self.assertEqual('original', obj.test_attr)
1659
1639
# NB: Don't delete this; it's not actually from 0.11!
1660
1640
@deprecated_function(deprecated_in((0, 11, 0)))
1804
1784
# make_branch_and_tree has to use local branch and repositories
1805
1785
# when the vfs transport and local disk are colocated, even if
1806
1786
# a different transport is in use for url generation.
1807
self.transport_server = test_server.FakeVFATServer
1787
from bzrlib.transport.fakevfat import FakeVFATServer
1788
self.transport_server = FakeVFATServer
1808
1789
self.assertFalse(self.get_url('t1').startswith('file://'))
1809
1790
tree = self.make_branch_and_tree('t1')
1810
1791
base = tree.bzrdir.root_transport.base
1948
1929
def test_transport_sftp(self):
1949
1930
self.requireFeature(features.paramiko)
1950
from bzrlib.tests import stub_sftp
1951
1931
self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1953
1933
def test_transport_memory(self):
1954
self.check_transport_set(memory.MemoryServer)
1934
self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1957
1937
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
2340
2320
os.chdir = orig_chdir
2341
2321
self.assertEqual(['foo', 'current'], chdirs)
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")
2349
2324
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2350
2325
"""Tests that really need to do things with an external bzr."""
2407
2382
simple_thunk_feature = tests._CompatabilityThunkFeature(
2408
deprecated_in((2, 1, 0)),
2409
'bzrlib.tests.test_selftest',
2410
'simple_thunk_feature','UnicodeFilename',
2411
replacement_module='bzrlib.tests'
2383
'bzrlib.tests', 'UnicodeFilename',
2384
'bzrlib.tests.test_selftest.simple_thunk_feature',
2385
deprecated_in((2,1,0)))
2414
2387
class Test_CompatibilityFeature(tests.TestCase):
2627
2600
# Running bzr in blackbox mode, normal/expected/user errors should be
2628
2601
# caught in the regular way and turned into an error message plus exit
2630
transport_server = memory.MemoryServer()
2603
transport_server = MemoryServer()
2631
2604
transport_server.start_server()
2632
2605
self.addCleanup(transport_server.stop_server)
2633
2606
url = transport_server.get_url()
2795
2764
# test doubles that supply a few sample tests to load, and check they
2798
def testmod_names():
2767
def _test_suite_testmod_names():
2799
2768
calls.append("testmod_names")
2801
2770
'bzrlib.tests.blackbox.test_branch',
2802
2771
'bzrlib.tests.per_transport',
2803
2772
'bzrlib.tests.test_selftest',
2805
self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2774
original_testmod_names = tests._test_suite_testmod_names
2775
def _test_suite_modules_to_doctest():
2807
2776
calls.append("modules_to_doctest")
2810
2777
return ['bzrlib.timestamp']
2811
self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2778
orig_modules_to_doctest = tests._test_suite_modules_to_doctest
2779
def restore_names():
2780
tests._test_suite_testmod_names = original_testmod_names
2781
tests._test_suite_modules_to_doctest = orig_modules_to_doctest
2782
self.addCleanup(restore_names)
2783
tests._test_suite_testmod_names = _test_suite_testmod_names
2784
tests._test_suite_modules_to_doctest = _test_suite_modules_to_doctest
2812
2785
expected_test_list = [
2813
2786
# testmod_names
2814
2787
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
2815
2788
('bzrlib.tests.per_transport.TransportTests'
2816
2789
'.test_abspath(LocalTransport,LocalURLServer)'),
2817
2790
'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
2791
# modules_to_doctest
2792
'bzrlib.timestamp.format_highres_date',
2818
2793
# plugins can't be tested that way since selftest may be run with
2821
if __doc__ is not None:
2822
expected_test_list.extend([
2823
# modules_to_doctest
2824
'bzrlib.timestamp.format_highres_date',
2826
2796
suite = tests.test_suite()
2827
2797
self.assertEqual(set(["testmod_names", "modules_to_doctest"]),