~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2010-03-21 21:39:33 UTC
  • mfrom: (5102 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5143.
  • Revision ID: jelmer@samba.org-20100321213933-fexeh9zcoz8oaju2
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
1176
1186
            # because the default open will not open them and
1177
1187
            # they may not be initializable.
1178
1188
            return
 
1189
        # for remote formats, there must be no prior assumption about the
 
1190
        # network name to use - it's possible that this may somehow have got
 
1191
        # in through an unisolated test though - see
 
1192
        # <https://bugs.edge.launchpad.net/bzr/+bug/504102>
 
1193
        self.assertEquals(getattr(self.bzrdir_format,
 
1194
            '_network_name', None),
 
1195
            None)
1179
1196
        # supported formats must be able to init and open
1180
1197
        t = get_transport(self.get_url())
1181
1198
        readonly_t = get_transport(self.get_readonly_url())
1404
1421
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1405
1422
        self.assertEqual(made_control, made_branch.bzrdir)
1406
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
 
1407
1441
    def test_open_branch(self):
1408
1442
        if not self.bzrdir_format.is_supported():
1409
1443
            # unsupported formats are not loopback testable
1419
1453
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1420
1454
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1421
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
 
1422
1476
    def test_create_repository(self):
1423
1477
        # a bzrdir can construct a repository for itself.
1424
1478
        if not self.bzrdir_format.is_supported():
1790
1844
 
1791
1845
class TestBreakLock(TestCaseWithBzrDir):
1792
1846
 
1793
 
    def setUp(self):
1794
 
        super(TestBreakLock, self).setUp()
1795
 
        # we want a UI factory that accepts canned input for the tests:
1796
 
        # while SilentUIFactory still accepts stdin, we need to customise
1797
 
        # ours
1798
 
        self.old_factory = bzrlib.ui.ui_factory
1799
 
        self.addCleanup(self.restoreFactory)
1800
 
 
1801
 
    def restoreFactory(self):
1802
 
        bzrlib.ui.ui_factory = self.old_factory
1803
 
 
1804
1847
    def test_break_lock_empty(self):
1805
1848
        # break lock on an empty bzrdir should work silently.
1806
1849
        dir = self.make_bzrdir('.')
1843
1886
        thisdir = self.make_bzrdir('this')
1844
1887
        try:
1845
1888
            bzrlib.branch.BranchReferenceFormat().initialize(
1846
 
                thisdir, master)
 
1889
                thisdir, target_branch=master)
1847
1890
        except errors.IncompatibleFormat:
1848
1891
            return
1849
1892
        unused_repo = thisdir.create_repository()