~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

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 (
248
247
        try:
249
248
            bzrdir.destroy_branch()
250
249
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
251
 
            raise TestNotApplicable('Format does not support destroying tree')
 
250
            raise TestNotApplicable('Format does not support destroying branch')
252
251
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
253
252
        bzrdir.create_branch()
254
253
        bzrdir.open_branch()
255
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
 
256
266
    def test_destroy_repository(self):
257
267
        repo = self.make_repository('repository')
258
268
        bzrdir = repo.bzrdir
524
534
        dir = self.make_bzrdir('source')
525
535
        try:
526
536
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
527
 
                referenced_branch)
 
537
                target_branch=referenced_branch)
528
538
        except errors.IncompatibleFormat:
529
539
            # this is ok too, not all formats have to support references.
530
540
            return
627
637
        dir = self.make_bzrdir('source')
628
638
        try:
629
639
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
630
 
                referenced_branch)
 
640
                target_branch=referenced_branch)
631
641
        except errors.IncompatibleFormat:
632
642
            # this is ok too, not all formats have to support references.
633
643
            return
692
702
        dir = self.make_bzrdir('source')
693
703
        try:
694
704
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
695
 
                referenced_branch)
 
705
                target_branch=referenced_branch)
696
706
        except errors.IncompatibleFormat:
697
707
            # this is ok too, not all formats have to support references.
698
708
            return
967
977
        dir = self.make_bzrdir('source')
968
978
        try:
969
979
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
970
 
                referenced_branch)
 
980
                target_branch=referenced_branch)
971
981
        except errors.IncompatibleFormat:
972
982
            # this is ok too, not all formats have to support references.
973
983
            return
987
997
        dir = self.make_bzrdir('source')
988
998
        try:
989
999
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
990
 
                referenced_tree.branch)
 
1000
                target_branch=referenced_tree.branch)
991
1001
        except errors.IncompatibleFormat:
992
1002
            # this is ok too, not all formats have to support references.
993
1003
            return
1013
1023
        dir = self.make_bzrdir('source')
1014
1024
        try:
1015
1025
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1016
 
                referenced_tree.branch)
 
1026
                target_branch=referenced_tree.branch)
1017
1027
        except errors.IncompatibleFormat:
1018
1028
            # this is ok too, not all formats have to support references.
1019
1029
            return
1078
1088
        dir = self.make_bzrdir('source')
1079
1089
        try:
1080
1090
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1081
 
                referenced_branch)
 
1091
                target_branch=referenced_branch)
1082
1092
        except errors.IncompatibleFormat:
1083
1093
            # this is ok too, not all formats have to support references.
1084
1094
            return
1104
1114
        dir = self.make_bzrdir('source')
1105
1115
        try:
1106
1116
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
1107
 
                referenced_branch)
 
1117
                target_branch=referenced_branch)
1108
1118
        except errors.IncompatibleFormat:
1109
1119
            # this is ok too, not all formats have to support references.
1110
1120
            return
1411
1421
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1412
1422
        self.assertEqual(made_control, made_branch.bzrdir)
1413
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
 
1414
1441
    def test_open_branch(self):
1415
1442
        if not self.bzrdir_format.is_supported():
1416
1443
            # unsupported formats are not loopback testable
1426
1453
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1427
1454
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1428
1455
 
 
1456
    def test_list_branches(self):
 
1457
        if not self.bzrdir_format.is_supported():
 
1458
            # unsupported formats are not loopback testable
 
1459
            # because the default open will not open them and
 
1460
            # they may not be initializable.
 
1461
            return
 
1462
        t = get_transport(self.get_url())
 
1463
        made_control = self.bzrdir_format.initialize(t.base)
 
1464
        made_repo = made_control.create_repository()
 
1465
        made_branch = made_control.create_branch()
 
1466
        branches = made_control.list_branches()
 
1467
        self.assertEquals(1, len(branches))
 
1468
        self.assertEquals(made_branch.base, branches[0].base)
 
1469
        try:
 
1470
            made_control.destroy_branch()
 
1471
        except errors.UnsupportedOperation:
 
1472
            pass # Not all bzrdirs support destroying directories
 
1473
        else:
 
1474
            self.assertEquals([], made_control.list_branches())
 
1475
 
1429
1476
    def test_create_repository(self):
1430
1477
        # a bzrdir can construct a repository for itself.
1431
1478
        if not self.bzrdir_format.is_supported():
1797
1844
 
1798
1845
class TestBreakLock(TestCaseWithBzrDir):
1799
1846
 
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
1847
    def test_break_lock_empty(self):
1812
1848
        # break lock on an empty bzrdir should work silently.
1813
1849
        dir = self.make_bzrdir('.')
1850
1886
        thisdir = self.make_bzrdir('this')
1851
1887
        try:
1852
1888
            bzrlib.branch.BranchReferenceFormat().initialize(
1853
 
                thisdir, master)
 
1889
                thisdir, target_branch=master)
1854
1890
        except errors.IncompatibleFormat:
1855
1891
            return
1856
1892
        unused_repo = thisdir.create_repository()