~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_bzrdir/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    bzrdir,
28
28
    check,
29
 
    controldir,
30
29
    errors,
31
30
    gpg,
 
31
    lockdir,
32
32
    osutils,
 
33
    repository,
33
34
    revision as _mod_revision,
 
35
    transactions,
34
36
    transport,
35
37
    ui,
36
38
    urlutils,
37
39
    workingtree,
38
40
    )
39
 
from bzrlib.errors import (NoSuchRevision,
 
41
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
 
42
from bzrlib.errors import (FileExists,
 
43
                           NoSuchRevision,
 
44
                           NoSuchFile,
 
45
                           UninitializableFormat,
40
46
                           NotBranchError,
41
47
                           )
42
48
import bzrlib.revision
43
49
from bzrlib.tests import (
44
50
                          ChrootedTestCase,
 
51
                          TestCase,
 
52
                          TestCaseWithTransport,
45
53
                          TestNotApplicable,
46
54
                          TestSkipped,
47
55
                          )
48
 
from bzrlib.tests.per_controldir import TestCaseWithControlDir
 
56
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
 
57
from bzrlib.trace import mutter
 
58
from bzrlib.transport import get_transport
49
59
from bzrlib.transport.local import LocalTransport
50
60
from bzrlib.ui import (
51
61
    CannedInputUIFactory,
52
62
    )
 
63
from bzrlib.upgrade import upgrade
53
64
from bzrlib.remote import RemoteBzrDir, RemoteRepository
54
65
from bzrlib.repofmt import weaverepo
55
66
 
56
67
 
57
 
class TestControlDir(TestCaseWithControlDir):
 
68
class TestBzrDir(TestCaseWithBzrDir):
58
69
    # Many of these tests test for disk equality rather than checking
59
70
    # for semantic equivalence. This works well for some tests but
60
71
    # is not good at handling changes in representation or the addition
191
202
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
192
203
        TestSkipped.  Returns the newly sprouted bzrdir.
193
204
        """
194
 
        to_transport = transport.get_transport(to_url)
 
205
        to_transport = get_transport(to_url)
195
206
        if not isinstance(to_transport, LocalTransport):
196
207
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
197
208
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
241
252
        bzrdir.create_branch()
242
253
        bzrdir.open_branch()
243
254
 
 
255
    def test_destroy_colocated_branch(self):
 
256
        branch = self.make_branch('branch')
 
257
        bzrdir = branch.bzrdir
 
258
        try:
 
259
            colo_branch = bzrdir.create_branch('colo')
 
260
        except errors.NoColocatedBranchSupport:
 
261
            raise TestNotApplicable('BzrDir does not do colocated branches')
 
262
        bzrdir.destroy_branch("colo")
 
263
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch, 
 
264
                          "colo")
 
265
 
244
266
    def test_destroy_repository(self):
245
267
        repo = self.make_repository('repository')
246
268
        bzrdir = repo.bzrdir
254
276
        bzrdir.open_repository()
255
277
 
256
278
    def test_open_workingtree_raises_no_working_tree(self):
257
 
        """ControlDir.open_workingtree() should raise NoWorkingTree (rather than
 
279
        """BzrDir.open_workingtree() should raise NoWorkingTree (rather than
258
280
        e.g. NotLocalUrl) if there is no working tree.
259
281
        """
260
282
        dir = self.make_bzrdir('source')
261
283
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
262
284
        if vfs_dir.has_workingtree():
263
 
            # This ControlDir format doesn't support ControlDirs without
264
 
            # working trees, so this test is irrelevant.
 
285
            # This BzrDir format doesn't support BzrDirs without working trees,
 
286
            # so this test is irrelevant.
265
287
            return
266
288
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
267
289
 
1157
1179
        self.assertEqual(tree.branch.last_revision(),
1158
1180
                         target.open_branch().last_revision())
1159
1181
 
1160
 
    def test_sprout_with_revision_id_uses_default_stack_on(self):
1161
 
        # Make a branch with three commits to stack on.
1162
 
        builder = self.make_branch_builder('stack-on')
1163
 
        builder.start_series()
1164
 
        builder.build_commit(message='Rev 1.', rev_id='rev-1')
1165
 
        builder.build_commit(message='Rev 2.', rev_id='rev-2')
1166
 
        builder.build_commit(message='Rev 3.', rev_id='rev-3')
1167
 
        builder.finish_series()
1168
 
        stack_on = builder.get_branch()
1169
 
        # Make a bzrdir with a default stacking policy to stack on that branch.
1170
 
        config = self.make_bzrdir('policy-dir').get_config()
1171
 
        try:
1172
 
            config.set_default_stack_on(self.get_url('stack-on'))
1173
 
        except errors.BzrError:
1174
 
            raise TestNotApplicable('Only relevant for stackable formats.')
1175
 
        # Sprout the stacked-on branch into the bzrdir.
1176
 
        sprouted = stack_on.bzrdir.sprout(
1177
 
            self.get_url('policy-dir/sprouted'), revision_id='rev-3')
1178
 
        # Not all revisions are copied into the sprouted repository.
1179
 
        repo = sprouted.open_repository()
1180
 
        self.addCleanup(repo.lock_read().unlock)
1181
 
        self.assertEqual(None, repo.get_parent_map(['rev-1']).get('rev-1'))
1182
 
 
1183
1182
    def test_format_initialize_find_open(self):
1184
1183
        # loopback test to check the current format initializes to itself.
1185
1184
        if not self.bzrdir_format.is_supported():
1190
1189
        # for remote formats, there must be no prior assumption about the
1191
1190
        # network name to use - it's possible that this may somehow have got
1192
1191
        # in through an unisolated test though - see
1193
 
        # <https://bugs.launchpad.net/bzr/+bug/504102>
 
1192
        # <https://bugs.edge.launchpad.net/bzr/+bug/504102>
1194
1193
        self.assertEquals(getattr(self.bzrdir_format,
1195
1194
            '_network_name', None),
1196
1195
            None)
1197
1196
        # supported formats must be able to init and open
1198
 
        t = transport.get_transport(self.get_url())
1199
 
        readonly_t = transport.get_transport(self.get_readonly_url())
 
1197
        t = get_transport(self.get_url())
 
1198
        readonly_t = get_transport(self.get_readonly_url())
1200
1199
        made_control = self.bzrdir_format.initialize(t.base)
1201
 
        self.failUnless(isinstance(made_control, controldir.ControlDir))
 
1200
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
1202
1201
        self.assertEqual(self.bzrdir_format,
1203
 
                         controldir.ControlDirFormat.find_format(readonly_t))
 
1202
                         bzrdir.BzrDirFormat.find_format(readonly_t))
1204
1203
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1205
1204
        opened_dir = bzrdir.BzrDir.open(t.base)
1206
1205
        self.assertEqual(made_control._format,
1207
1206
                         opened_dir._format)
1208
1207
        self.assertEqual(direct_opened_dir._format,
1209
1208
                         opened_dir._format)
1210
 
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
 
1209
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
1211
1210
 
1212
1211
    def test_format_initialize_on_transport_ex(self):
1213
1212
        t = self.get_transport('dir')
1406
1405
        # test the formats specific behaviour for no-content or similar dirs.
1407
1406
        self.assertRaises(NotBranchError,
1408
1407
                          self.bzrdir_format.open,
1409
 
                          transport.get_transport(self.get_readonly_url()))
 
1408
                          get_transport(self.get_readonly_url()))
1410
1409
 
1411
1410
    def test_create_branch(self):
1412
1411
        # a bzrdir can construct a branch and repository for itself.
1415
1414
            # because the default open will not open them and
1416
1415
            # they may not be initializable.
1417
1416
            return
1418
 
        t = transport.get_transport(self.get_url())
 
1417
        t = get_transport(self.get_url())
1419
1418
        made_control = self.bzrdir_format.initialize(t.base)
1420
1419
        made_repo = made_control.create_repository()
1421
1420
        made_branch = made_control.create_branch()
1422
1421
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1423
1422
        self.assertEqual(made_control, made_branch.bzrdir)
1424
1423
 
 
1424
    def test_create_colo_branch(self):
 
1425
        # a bzrdir can construct a branch and repository for itself.
 
1426
        if not self.bzrdir_format.is_supported():
 
1427
            # unsupported formats are not loopback testable
 
1428
            # because the default open will not open them and
 
1429
            # they may not be initializable.
 
1430
            raise TestNotApplicable('Control dir format not supported')
 
1431
        t = get_transport(self.get_url())
 
1432
        made_control = self.bzrdir_format.initialize(t.base)
 
1433
        made_repo = made_control.create_repository()
 
1434
        try:
 
1435
            made_branch = made_control.create_branch("colo")
 
1436
        except errors.NoColocatedBranchSupport:
 
1437
            raise TestNotApplicable('Colocated branches not supported')
 
1438
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
1439
        self.assertEqual(made_control, made_branch.bzrdir)
 
1440
 
1425
1441
    def test_open_branch(self):
1426
1442
        if not self.bzrdir_format.is_supported():
1427
1443
            # unsupported formats are not loopback testable
1428
1444
            # because the default open will not open them and
1429
1445
            # they may not be initializable.
1430
1446
            return
1431
 
        t = transport.get_transport(self.get_url())
 
1447
        t = get_transport(self.get_url())
1432
1448
        made_control = self.bzrdir_format.initialize(t.base)
1433
1449
        made_repo = made_control.create_repository()
1434
1450
        made_branch = made_control.create_branch()
1443
1459
            # because the default open will not open them and
1444
1460
            # they may not be initializable.
1445
1461
            return
1446
 
        t = transport.get_transport(self.get_url())
 
1462
        t = get_transport(self.get_url())
1447
1463
        made_control = self.bzrdir_format.initialize(t.base)
1448
1464
        made_repo = made_control.create_repository()
1449
1465
        made_branch = made_control.create_branch()
1464
1480
            # because the default open will not open them and
1465
1481
            # they may not be initializable.
1466
1482
            return
1467
 
        t = transport.get_transport(self.get_url())
 
1483
        t = get_transport(self.get_url())
1468
1484
        made_control = self.bzrdir_format.initialize(t.base)
1469
1485
        made_repo = made_control.create_repository()
1470
1486
        # Check that we have a repository object.
1479
1495
            # because the default open will not open them and
1480
1496
            # they may not be initializable.
1481
1497
            return
1482
 
        t = transport.get_transport(self.get_url())
 
1498
        t = get_transport(self.get_url())
1483
1499
        made_control = self.bzrdir_format.initialize(t.base)
1484
1500
        try:
1485
1501
            made_repo = made_control.create_repository(shared=True)
1496
1512
            # because the default open will not open them and
1497
1513
            # they may not be initializable.
1498
1514
            return
1499
 
        t = transport.get_transport(self.get_url())
 
1515
        t = get_transport(self.get_url())
1500
1516
        made_control = self.bzrdir_format.initialize(t.base)
1501
1517
        made_repo = made_control.create_repository(shared=False)
1502
1518
        self.assertFalse(made_repo.is_shared())
1507
1523
            # because the default open will not open them and
1508
1524
            # they may not be initializable.
1509
1525
            return
1510
 
        t = transport.get_transport(self.get_url())
 
1526
        t = get_transport(self.get_url())
1511
1527
        made_control = self.bzrdir_format.initialize(t.base)
1512
1528
        made_repo = made_control.create_repository()
1513
1529
        opened_repo = made_control.open_repository()
1635
1651
    def test_root_transport(self):
1636
1652
        dir = self.make_bzrdir('.')
1637
1653
        self.assertEqual(dir.root_transport.base,
1638
 
                         transport.get_transport(self.get_url('.')).base)
 
1654
                         get_transport(self.get_url('.')).base)
1639
1655
 
1640
1656
    def test_find_repository_no_repo_under_standalone_branch(self):
1641
1657
        # finding a repo stops at standalone branches even if there is a
1646
1662
            # need a shared repository to test this.
1647
1663
            return
1648
1664
        url = self.get_url('intermediate')
1649
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1650
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1665
        get_transport(self.get_url()).mkdir('intermediate')
 
1666
        get_transport(self.get_url()).mkdir('intermediate/child')
1651
1667
        made_control = self.bzrdir_format.initialize(url)
1652
1668
        made_control.create_repository()
1653
1669
        innermost_control = self.bzrdir_format.initialize(
1671
1687
            # need a shared repository to test this.
1672
1688
            return
1673
1689
        url = self.get_url('childbzrdir')
1674
 
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
 
1690
        get_transport(self.get_url()).mkdir('childbzrdir')
1675
1691
        made_control = self.bzrdir_format.initialize(url)
1676
1692
        try:
1677
1693
            child_repo = made_control.open_repository()
1705
1721
            # need a shared repository to test this.
1706
1722
            return
1707
1723
        url = self.get_url('childrepo')
1708
 
        transport.get_transport(self.get_url()).mkdir('childrepo')
 
1724
        get_transport(self.get_url()).mkdir('childrepo')
1709
1725
        child_control = self.bzrdir_format.initialize(url)
1710
1726
        child_repo = child_control.create_repository(shared=True)
1711
1727
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1724
1740
            # need a shared repository to test this.
1725
1741
            return
1726
1742
        url = self.get_url('intermediate')
1727
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1728
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1743
        get_transport(self.get_url()).mkdir('intermediate')
 
1744
        get_transport(self.get_url()).mkdir('intermediate/child')
1729
1745
        made_control = self.bzrdir_format.initialize(url)
1730
1746
        try:
1731
1747
            child_repo = made_control.open_repository()
1757
1773
            self.assertTrue(isinstance(dir._format.get_converter(
1758
1774
                format=dir._format), bzrdir.Converter))
1759
1775
        dir.needs_format_conversion(
1760
 
            controldir.ControlDirFormat.get_default_format())
 
1776
            bzrdir.BzrDirFormat.get_default_format())
1761
1777
 
1762
1778
    def test_backup_copies_existing(self):
1763
1779
        tree = self.make_branch_and_tree('test')
1826
1842
            bd.retire_bzrdir, limit=0)
1827
1843
 
1828
1844
 
1829
 
class TestBreakLock(TestCaseWithControlDir):
 
1845
class TestBreakLock(TestCaseWithBzrDir):
1830
1846
 
1831
1847
    def test_break_lock_empty(self):
1832
1848
        # break lock on an empty bzrdir should work silently.
1934
1950
        self.assertRaises(errors.LockBroken, tree.unlock)
1935
1951
 
1936
1952
 
1937
 
class TestTransportConfig(TestCaseWithControlDir):
 
1953
class TestTransportConfig(TestCaseWithBzrDir):
1938
1954
 
1939
1955
    def test_get_config(self):
1940
1956
        my_dir = self.make_bzrdir('.')
1956
1972
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1957
1973
 
1958
1974
 
1959
 
class ChrootedControlDirTests(ChrootedTestCase):
 
1975
class ChrootedBzrDirTests(ChrootedTestCase):
1960
1976
 
1961
1977
    def test_find_repository_no_repository(self):
1962
1978
        # loopback test to check the current format fails to find a
1970
1986
        # - do the vfs initialisation over the basic vfs transport
1971
1987
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1972
1988
        url = self.get_vfs_only_url('subdir')
1973
 
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1989
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
1974
1990
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1975
1991
        try:
1976
1992
            repo = made_control.open_repository()
1983
1999
        self.assertRaises(errors.NoRepositoryPresent,
1984
2000
                          made_control.find_repository)
1985
2001
 
1986
 
 
1987
 
class TestControlDirControlComponent(TestCaseWithControlDir):
1988
 
    """ControlDir implementations adequately implement ControlComponent."""
1989
 
 
1990
 
    def test_urls(self):
1991
 
        bd = self.make_bzrdir('bd')
1992
 
        self.assertIsInstance(bd.user_url, str)
1993
 
        self.assertEqual(bd.user_url, bd.user_transport.base)
1994
 
        # for all current bzrdir implementations the user dir must be 
1995
 
        # above the control dir but we might need to relax that?
1996
 
        self.assertEqual(bd.control_url.find(bd.user_url), 0)
1997
 
        self.assertEqual(bd.control_url, bd.control_transport.base)