~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from itertools import izip
22
22
import os
23
23
from stat import S_ISDIR
24
 
import sys
25
24
 
26
25
import bzrlib.branch
27
26
from bzrlib import (
56
55
                          )
57
56
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
58
57
from bzrlib.trace import mutter
59
 
from bzrlib.transport import get_transport
60
58
from bzrlib.transport.local import LocalTransport
61
59
from bzrlib.ui import (
62
60
    CannedInputUIFactory,
203
201
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
204
202
        TestSkipped.  Returns the newly sprouted bzrdir.
205
203
        """
206
 
        to_transport = get_transport(to_url)
 
204
        to_transport = transport.get_transport(to_url)
207
205
        if not isinstance(to_transport, LocalTransport):
208
206
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
209
207
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
248
246
        try:
249
247
            bzrdir.destroy_branch()
250
248
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
251
 
            raise TestNotApplicable('Format does not support destroying tree')
 
249
            raise TestNotApplicable('Format does not support destroying branch')
252
250
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
253
251
        bzrdir.create_branch()
254
252
        bzrdir.open_branch()
524
522
        dir = self.make_bzrdir('source')
525
523
        try:
526
524
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
527
 
                referenced_branch)
 
525
                target_branch=referenced_branch)
528
526
        except errors.IncompatibleFormat:
529
527
            # this is ok too, not all formats have to support references.
530
528
            return
627
625
        dir = self.make_bzrdir('source')
628
626
        try:
629
627
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
630
 
                referenced_branch)
 
628
                target_branch=referenced_branch)
631
629
        except errors.IncompatibleFormat:
632
630
            # this is ok too, not all formats have to support references.
633
631
            return
692
690
        dir = self.make_bzrdir('source')
693
691
        try:
694
692
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
695
 
                referenced_branch)
 
693
                target_branch=referenced_branch)
696
694
        except errors.IncompatibleFormat:
697
695
            # this is ok too, not all formats have to support references.
698
696
            return
967
965
        dir = self.make_bzrdir('source')
968
966
        try:
969
967
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
970
 
                referenced_branch)
 
968
                target_branch=referenced_branch)
971
969
        except errors.IncompatibleFormat:
972
970
            # this is ok too, not all formats have to support references.
973
971
            return
987
985
        dir = self.make_bzrdir('source')
988
986
        try:
989
987
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
990
 
                referenced_tree.branch)
 
988
                target_branch=referenced_tree.branch)
991
989
        except errors.IncompatibleFormat:
992
990
            # this is ok too, not all formats have to support references.
993
991
            return
1013
1011
        dir = self.make_bzrdir('source')
1014
1012
        try:
1015
1013
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1016
 
                referenced_tree.branch)
 
1014
                target_branch=referenced_tree.branch)
1017
1015
        except errors.IncompatibleFormat:
1018
1016
            # this is ok too, not all formats have to support references.
1019
1017
            return
1078
1076
        dir = self.make_bzrdir('source')
1079
1077
        try:
1080
1078
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1081
 
                referenced_branch)
 
1079
                target_branch=referenced_branch)
1082
1080
        except errors.IncompatibleFormat:
1083
1081
            # this is ok too, not all formats have to support references.
1084
1082
            return
1104
1102
        dir = self.make_bzrdir('source')
1105
1103
        try:
1106
1104
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1107
 
                referenced_branch)
 
1105
                target_branch=referenced_branch)
1108
1106
        except errors.IncompatibleFormat:
1109
1107
            # this is ok too, not all formats have to support references.
1110
1108
            return
1169
1167
        self.assertEqual(tree.branch.last_revision(),
1170
1168
                         target.open_branch().last_revision())
1171
1169
 
 
1170
    def test_sprout_with_revision_id_uses_default_stack_on(self):
 
1171
        # Make a branch with three commits to stack on.
 
1172
        builder = self.make_branch_builder('stack-on')
 
1173
        builder.start_series()
 
1174
        builder.build_commit(message='Rev 1.', rev_id='rev-1')
 
1175
        builder.build_commit(message='Rev 2.', rev_id='rev-2')
 
1176
        builder.build_commit(message='Rev 3.', rev_id='rev-3')
 
1177
        builder.finish_series()
 
1178
        stack_on = builder.get_branch()
 
1179
        # Make a bzrdir with a default stacking policy to stack on that branch.
 
1180
        config = self.make_bzrdir('policy-dir').get_config()
 
1181
        try:
 
1182
            config.set_default_stack_on(self.get_url('stack-on'))
 
1183
        except errors.BzrError:
 
1184
            raise TestNotApplicable('Only relevant for stackable formats.')
 
1185
        # Sprout the stacked-on branch into the bzrdir.
 
1186
        sprouted = stack_on.bzrdir.sprout(
 
1187
            self.get_url('policy-dir/sprouted'), revision_id='rev-3')
 
1188
        # Not all revisions are copied into the sprouted repository.
 
1189
        repo = sprouted.open_repository()
 
1190
        self.addCleanup(repo.lock_read().unlock)
 
1191
        self.assertEqual(None, repo.get_parent_map(['rev-1']).get('rev-1'))
 
1192
 
1172
1193
    def test_format_initialize_find_open(self):
1173
1194
        # loopback test to check the current format initializes to itself.
1174
1195
        if not self.bzrdir_format.is_supported():
1179
1200
        # for remote formats, there must be no prior assumption about the
1180
1201
        # network name to use - it's possible that this may somehow have got
1181
1202
        # in through an unisolated test though - see
1182
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/504102>
 
1203
        # <https://bugs.launchpad.net/bzr/+bug/504102>
1183
1204
        self.assertEquals(getattr(self.bzrdir_format,
1184
1205
            '_network_name', None),
1185
1206
            None)
1186
1207
        # supported formats must be able to init and open
1187
 
        t = get_transport(self.get_url())
1188
 
        readonly_t = get_transport(self.get_readonly_url())
 
1208
        t = transport.get_transport(self.get_url())
 
1209
        readonly_t = transport.get_transport(self.get_readonly_url())
1189
1210
        made_control = self.bzrdir_format.initialize(t.base)
1190
1211
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
1191
1212
        self.assertEqual(self.bzrdir_format,
1395
1416
        # test the formats specific behaviour for no-content or similar dirs.
1396
1417
        self.assertRaises(NotBranchError,
1397
1418
                          self.bzrdir_format.open,
1398
 
                          get_transport(self.get_readonly_url()))
 
1419
                          transport.get_transport(self.get_readonly_url()))
1399
1420
 
1400
1421
    def test_create_branch(self):
1401
1422
        # a bzrdir can construct a branch and repository for itself.
1404
1425
            # because the default open will not open them and
1405
1426
            # they may not be initializable.
1406
1427
            return
1407
 
        t = get_transport(self.get_url())
 
1428
        t = transport.get_transport(self.get_url())
1408
1429
        made_control = self.bzrdir_format.initialize(t.base)
1409
1430
        made_repo = made_control.create_repository()
1410
1431
        made_branch = made_control.create_branch()
1417
1438
            # because the default open will not open them and
1418
1439
            # they may not be initializable.
1419
1440
            return
1420
 
        t = get_transport(self.get_url())
 
1441
        t = transport.get_transport(self.get_url())
1421
1442
        made_control = self.bzrdir_format.initialize(t.base)
1422
1443
        made_repo = made_control.create_repository()
1423
1444
        made_branch = made_control.create_branch()
1426
1447
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1427
1448
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1428
1449
 
 
1450
    def test_list_branches(self):
 
1451
        if not self.bzrdir_format.is_supported():
 
1452
            # unsupported formats are not loopback testable
 
1453
            # because the default open will not open them and
 
1454
            # they may not be initializable.
 
1455
            return
 
1456
        t = transport.get_transport(self.get_url())
 
1457
        made_control = self.bzrdir_format.initialize(t.base)
 
1458
        made_repo = made_control.create_repository()
 
1459
        made_branch = made_control.create_branch()
 
1460
        branches = made_control.list_branches()
 
1461
        self.assertEquals(1, len(branches))
 
1462
        self.assertEquals(made_branch.base, branches[0].base)
 
1463
        try:
 
1464
            made_control.destroy_branch()
 
1465
        except errors.UnsupportedOperation:
 
1466
            pass # Not all bzrdirs support destroying directories
 
1467
        else:
 
1468
            self.assertEquals([], made_control.list_branches())
 
1469
 
1429
1470
    def test_create_repository(self):
1430
1471
        # a bzrdir can construct a repository for itself.
1431
1472
        if not self.bzrdir_format.is_supported():
1433
1474
            # because the default open will not open them and
1434
1475
            # they may not be initializable.
1435
1476
            return
1436
 
        t = get_transport(self.get_url())
 
1477
        t = transport.get_transport(self.get_url())
1437
1478
        made_control = self.bzrdir_format.initialize(t.base)
1438
1479
        made_repo = made_control.create_repository()
1439
1480
        # Check that we have a repository object.
1448
1489
            # because the default open will not open them and
1449
1490
            # they may not be initializable.
1450
1491
            return
1451
 
        t = get_transport(self.get_url())
 
1492
        t = transport.get_transport(self.get_url())
1452
1493
        made_control = self.bzrdir_format.initialize(t.base)
1453
1494
        try:
1454
1495
            made_repo = made_control.create_repository(shared=True)
1465
1506
            # because the default open will not open them and
1466
1507
            # they may not be initializable.
1467
1508
            return
1468
 
        t = get_transport(self.get_url())
 
1509
        t = transport.get_transport(self.get_url())
1469
1510
        made_control = self.bzrdir_format.initialize(t.base)
1470
1511
        made_repo = made_control.create_repository(shared=False)
1471
1512
        self.assertFalse(made_repo.is_shared())
1476
1517
            # because the default open will not open them and
1477
1518
            # they may not be initializable.
1478
1519
            return
1479
 
        t = get_transport(self.get_url())
 
1520
        t = transport.get_transport(self.get_url())
1480
1521
        made_control = self.bzrdir_format.initialize(t.base)
1481
1522
        made_repo = made_control.create_repository()
1482
1523
        opened_repo = made_control.open_repository()
1604
1645
    def test_root_transport(self):
1605
1646
        dir = self.make_bzrdir('.')
1606
1647
        self.assertEqual(dir.root_transport.base,
1607
 
                         get_transport(self.get_url('.')).base)
 
1648
                         transport.get_transport(self.get_url('.')).base)
1608
1649
 
1609
1650
    def test_find_repository_no_repo_under_standalone_branch(self):
1610
1651
        # finding a repo stops at standalone branches even if there is a
1615
1656
            # need a shared repository to test this.
1616
1657
            return
1617
1658
        url = self.get_url('intermediate')
1618
 
        get_transport(self.get_url()).mkdir('intermediate')
1619
 
        get_transport(self.get_url()).mkdir('intermediate/child')
 
1659
        transport.get_transport(self.get_url()).mkdir('intermediate')
 
1660
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
1620
1661
        made_control = self.bzrdir_format.initialize(url)
1621
1662
        made_control.create_repository()
1622
1663
        innermost_control = self.bzrdir_format.initialize(
1640
1681
            # need a shared repository to test this.
1641
1682
            return
1642
1683
        url = self.get_url('childbzrdir')
1643
 
        get_transport(self.get_url()).mkdir('childbzrdir')
 
1684
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
1644
1685
        made_control = self.bzrdir_format.initialize(url)
1645
1686
        try:
1646
1687
            child_repo = made_control.open_repository()
1674
1715
            # need a shared repository to test this.
1675
1716
            return
1676
1717
        url = self.get_url('childrepo')
1677
 
        get_transport(self.get_url()).mkdir('childrepo')
 
1718
        transport.get_transport(self.get_url()).mkdir('childrepo')
1678
1719
        child_control = self.bzrdir_format.initialize(url)
1679
1720
        child_repo = child_control.create_repository(shared=True)
1680
1721
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1693
1734
            # need a shared repository to test this.
1694
1735
            return
1695
1736
        url = self.get_url('intermediate')
1696
 
        get_transport(self.get_url()).mkdir('intermediate')
1697
 
        get_transport(self.get_url()).mkdir('intermediate/child')
 
1737
        transport.get_transport(self.get_url()).mkdir('intermediate')
 
1738
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
1698
1739
        made_control = self.bzrdir_format.initialize(url)
1699
1740
        try:
1700
1741
            child_repo = made_control.open_repository()
1797
1838
 
1798
1839
class TestBreakLock(TestCaseWithBzrDir):
1799
1840
 
1800
 
    def setUp(self):
1801
 
        super(TestBreakLock, self).setUp()
1802
 
        # we want a UI factory that accepts canned input for the tests:
1803
 
        # while SilentUIFactory still accepts stdin, we need to customise
1804
 
        # ours
1805
 
        self.old_factory = bzrlib.ui.ui_factory
1806
 
        self.addCleanup(self.restoreFactory)
1807
 
 
1808
 
    def restoreFactory(self):
1809
 
        bzrlib.ui.ui_factory = self.old_factory
1810
 
 
1811
1841
    def test_break_lock_empty(self):
1812
1842
        # break lock on an empty bzrdir should work silently.
1813
1843
        dir = self.make_bzrdir('.')
1850
1880
        thisdir = self.make_bzrdir('this')
1851
1881
        try:
1852
1882
            bzrlib.branch.BranchReferenceFormat().initialize(
1853
 
                thisdir, master)
 
1883
                thisdir, target_branch=master)
1854
1884
        except errors.IncompatibleFormat:
1855
1885
            return
1856
1886
        unused_repo = thisdir.create_repository()
1950
1980
        # - do the vfs initialisation over the basic vfs transport
1951
1981
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1952
1982
        url = self.get_vfs_only_url('subdir')
1953
 
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1983
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
1954
1984
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1955
1985
        try:
1956
1986
            repo = made_control.open_repository()
1963
1993
        self.assertRaises(errors.NoRepositoryPresent,
1964
1994
                          made_control.find_repository)
1965
1995
 
 
1996
 
 
1997
class TestBzrDirControlComponent(TestCaseWithBzrDir):
 
1998
    """BzrDir implementations adequately implement ControlComponent."""
 
1999
 
 
2000
    def test_urls(self):
 
2001
        bd = self.make_bzrdir('bd')
 
2002
        self.assertIsInstance(bd.user_url, str)
 
2003
        self.assertEqual(bd.user_url, bd.user_transport.base)
 
2004
        # for all current bzrdir implementations the user dir must be 
 
2005
        # above the control dir but we might need to relax that?
 
2006
        self.assertEqual(bd.control_url.find(bd.user_url), 0)
 
2007
        self.assertEqual(bd.control_url, bd.control_transport.base)