~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_controldir/test_controldir.py

(jelmer) Move get_{workingtree, branch,
 repository}_transport methods from ControlDir to BzrDir. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    )
51
51
 
52
52
 
53
 
class AnonymousTestBranchFormat(bzrlib.branch.BranchFormat):
54
 
    """An anonymous branch format (does not have a format string)"""
55
 
 
56
 
    def get_format_string(self):
57
 
        raise NotImplementedError(self.get_format_string)
58
 
 
59
 
 
60
 
class IdentifiableTestBranchFormat(bzrlib.branch.BranchFormat):
61
 
    """An identifable branch format (has a format string)"""
62
 
 
63
 
    def get_format_string(self):
64
 
        return "I have an identity"
65
 
 
66
 
 
67
 
class AnonymousTestRepositoryFormat(repository.RepositoryFormat):
68
 
    """An anonymous branch format (does not have a format string)"""
69
 
 
70
 
    def get_format_string(self):
71
 
        raise NotImplementedError(self.get_format_string)
72
 
 
73
 
 
74
 
class IdentifiableTestRepositoryFormat(repository.RepositoryFormat):
75
 
    """An identifable branch format (has a format string)"""
76
 
 
77
 
    def get_format_string(self):
78
 
        return "I have an identity"
79
 
 
80
 
 
81
 
class AnonymousTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
82
 
    """An anonymous branch format (does not have a format string)"""
83
 
 
84
 
    def get_format_string(self):
85
 
        raise NotImplementedError(self.get_format_string)
86
 
 
87
 
 
88
 
class IdentifiableTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
89
 
    """An identifable branch format (has a format string)"""
90
 
 
91
 
    def get_format_string(self):
92
 
        return "I have an identity"
93
 
 
94
 
 
95
53
class TestControlDir(TestCaseWithControlDir):
96
54
 
97
55
    def skipIfNoWorkingTree(self, a_bzrdir):
1316
1274
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1317
1275
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1318
1276
 
1319
 
    def test_get_branch_transport(self):
1320
 
        dir = self.make_bzrdir('.')
1321
 
        # without a format, get_branch_transport gives use a transport
1322
 
        # which -may- point to an existing dir.
1323
 
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1324
 
                                   transport.Transport))
1325
 
        # with a given format, either the bzr dir supports identifiable
1326
 
        # branches, or it supports anonymous branch formats, but not both.
1327
 
        anonymous_format = AnonymousTestBranchFormat()
1328
 
        identifiable_format = IdentifiableTestBranchFormat()
1329
 
        try:
1330
 
            found_transport = dir.get_branch_transport(anonymous_format)
1331
 
            self.assertRaises(errors.IncompatibleFormat,
1332
 
                              dir.get_branch_transport,
1333
 
                              identifiable_format)
1334
 
        except errors.IncompatibleFormat:
1335
 
            found_transport = dir.get_branch_transport(identifiable_format)
1336
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1337
 
        # and the dir which has been initialized for us must exist.
1338
 
        found_transport.list_dir('.')
1339
 
 
1340
 
    def test_get_repository_transport(self):
1341
 
        dir = self.make_bzrdir('.')
1342
 
        # without a format, get_repository_transport gives use a transport
1343
 
        # which -may- point to an existing dir.
1344
 
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1345
 
                                   transport.Transport))
1346
 
        # with a given format, either the bzr dir supports identifiable
1347
 
        # repositories, or it supports anonymous repository formats, but not both.
1348
 
        anonymous_format = AnonymousTestRepositoryFormat()
1349
 
        identifiable_format = IdentifiableTestRepositoryFormat()
1350
 
        try:
1351
 
            found_transport = dir.get_repository_transport(anonymous_format)
1352
 
            self.assertRaises(errors.IncompatibleFormat,
1353
 
                              dir.get_repository_transport,
1354
 
                              identifiable_format)
1355
 
        except errors.IncompatibleFormat:
1356
 
            found_transport = dir.get_repository_transport(identifiable_format)
1357
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1358
 
        # and the dir which has been initialized for us must exist.
1359
 
        found_transport.list_dir('.')
1360
 
 
1361
 
    def test_get_workingtree_transport(self):
1362
 
        dir = self.make_bzrdir('.')
1363
 
        # without a format, get_workingtree_transport gives use a transport
1364
 
        # which -may- point to an existing dir.
1365
 
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1366
 
                                   transport.Transport))
1367
 
        # with a given format, either the bzr dir supports identifiable
1368
 
        # trees, or it supports anonymous tree formats, but not both.
1369
 
        anonymous_format = AnonymousTestWorkingTreeFormat()
1370
 
        identifiable_format = IdentifiableTestWorkingTreeFormat()
1371
 
        try:
1372
 
            found_transport = dir.get_workingtree_transport(anonymous_format)
1373
 
            self.assertRaises(errors.IncompatibleFormat,
1374
 
                              dir.get_workingtree_transport,
1375
 
                              identifiable_format)
1376
 
        except errors.IncompatibleFormat:
1377
 
            found_transport = dir.get_workingtree_transport(identifiable_format)
1378
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1379
 
        # and the dir which has been initialized for us must exist.
1380
 
        found_transport.list_dir('.')
1381
 
 
1382
1277
    def test_root_transport(self):
1383
1278
        dir = self.make_bzrdir('.')
1384
1279
        self.assertEqual(dir.root_transport.base,