/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1553.5.68 by Martin Pool
Add new TestCaseWithTransport.assertIsDirectory() and tests
2
# 
1534.4.39 by Robert Collins
Basic BzrDir support.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
7
#
1534.4.39 by Robert Collins
Basic BzrDir support.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
12
#
1534.4.39 by Robert Collins
Basic BzrDir support.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the BzrDir facility and any format specific tests.
18
19
For interface contract tests, see tests/bzr_dir_implementations.
20
"""
21
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
22
import os.path
1534.4.39 by Robert Collins
Basic BzrDir support.
23
from StringIO import StringIO
24
2204.4.1 by Aaron Bentley
Add 'formats' help topic
25
from bzrlib import (
2100.3.35 by Aaron Bentley
equality operations on bzrdir
26
    bzrdir,
27
    errors,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
28
    help_topics,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
29
    repository,
2204.4.12 by Aaron Bentley
Deprecate bzrdir.BzrDirFormat.set_default_format
30
    symbol_versioning,
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
31
    urlutils,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
32
    workingtree,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
33
    )
1508.1.25 by Robert Collins
Update per review comments.
34
import bzrlib.branch
1534.4.39 by Robert Collins
Basic BzrDir support.
35
from bzrlib.errors import (NotBranchError,
36
                           UnknownFormatError,
37
                           UnsupportedFormatError,
38
                           )
2215.3.5 by Aaron Bentley
Add support for remote ls
39
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
2004.1.25 by v.ladeuil+lp at free
Shuffle http related test code. Hopefully it ends up at the right place :)
40
from bzrlib.tests.HttpServer import HttpServer
1534.4.39 by Robert Collins
Basic BzrDir support.
41
from bzrlib.transport import get_transport
42
from bzrlib.transport.memory import MemoryServer
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
43
from bzrlib.repofmt import knitrepo, weaverepo
1534.4.39 by Robert Collins
Basic BzrDir support.
44
45
46
class TestDefaultFormat(TestCase):
47
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
48
    def test_get_set_default_format(self):
1534.4.39 by Robert Collins
Basic BzrDir support.
49
        old_format = bzrdir.BzrDirFormat.get_default_format()
50
        # default is BzrDirFormat6
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
51
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
2204.4.12 by Aaron Bentley
Deprecate bzrdir.BzrDirFormat.set_default_format
52
        self.applyDeprecated(symbol_versioning.zero_fourteen, 
53
                             bzrdir.BzrDirFormat.set_default_format, 
54
                             SampleBzrDirFormat())
1534.4.39 by Robert Collins
Basic BzrDir support.
55
        # creating a bzr dir should now create an instrumented dir.
56
        try:
1685.1.42 by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly.
57
            result = bzrdir.BzrDir.create('memory:///')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
58
            self.failUnless(isinstance(result, SampleBzrDir))
1534.4.39 by Robert Collins
Basic BzrDir support.
59
        finally:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
60
            self.applyDeprecated(symbol_versioning.zero_fourteen,
61
                bzrdir.BzrDirFormat.set_default_format, old_format)
1534.4.39 by Robert Collins
Basic BzrDir support.
62
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
63
64
2204.4.1 by Aaron Bentley
Add 'formats' help topic
65
class TestFormatRegistry(TestCase):
66
67
    def make_format_registry(self):
68
        my_format_registry = bzrdir.BzrDirFormatRegistry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
69
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
70
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
71
            ' repositories', deprecated=True)
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
72
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir', 
73
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
74
        my_format_registry.register_metadir('knit',
75
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
76
            'Format using knits',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
77
            )
2100.3.17 by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree
78
        my_format_registry.register_metadir('experimental-knit3', 
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
79
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
80
            'Format using knits', 
2100.3.37 by Aaron Bentley
rename working tree format 4 to AB1 everywhere
81
            tree='WorkingTreeFormatAB1')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
82
        my_format_registry.set_default('knit')
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
83
        my_format_registry.register_metadir(
84
            'experimental-knit2',
85
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
86
            'Experimental successor to knit.  Use at your own risk.',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
87
            )
2230.3.53 by Aaron Bentley
Merge bzr.dev
88
        my_format_registry.register_metadir(
89
            'branch6',
90
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
91
            'Experimental successor to knit.  Use at your own risk.',
2230.3.1 by Aaron Bentley
Get branch6 creation working
92
            branch_format='BzrBranchFormat6')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
93
        return my_format_registry
94
95
    def test_format_registry(self):
96
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
97
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
98
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
99
        my_bzrdir = my_format_registry.make_bzrdir('weave')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
100
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
101
        my_bzrdir = my_format_registry.make_bzrdir('default')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
102
        self.assertIsInstance(my_bzrdir.repository_format, 
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
103
            knitrepo.RepositoryFormatKnit1)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
104
        my_bzrdir = my_format_registry.make_bzrdir('knit')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
105
        self.assertIsInstance(my_bzrdir.repository_format, 
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
106
            knitrepo.RepositoryFormatKnit1)
2100.3.17 by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree
107
        my_bzrdir = my_format_registry.make_bzrdir('experimental-knit3')
108
        self.assertIsInstance(my_bzrdir.repository_format, 
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
109
            knitrepo.RepositoryFormatKnit3)
2100.3.17 by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree
110
        self.assertIsInstance(my_bzrdir.workingtree_format, 
2100.3.37 by Aaron Bentley
rename working tree format 4 to AB1 everywhere
111
            workingtree.WorkingTreeFormatAB1)
2230.3.1 by Aaron Bentley
Get branch6 creation working
112
        my_bzrdir = my_format_registry.make_bzrdir('branch6')
2230.3.55 by Aaron Bentley
Updates from review
113
        self.assertIsInstance(my_bzrdir.get_branch_format(),
2230.3.1 by Aaron Bentley
Get branch6 creation working
114
                              bzrlib.branch.BzrBranchFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
115
116
    def test_get_help(self):
117
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
118
        self.assertEqual('Format registered lazily',
119
                         my_format_registry.get_help('lazy'))
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
120
        self.assertEqual('Format using knits', 
2204.4.1 by Aaron Bentley
Add 'formats' help topic
121
                         my_format_registry.get_help('knit'))
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
122
        self.assertEqual('Format using knits', 
2204.4.1 by Aaron Bentley
Add 'formats' help topic
123
                         my_format_registry.get_help('default'))
124
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
125
                         ' checkouts or shared repositories', 
126
                         my_format_registry.get_help('weave'))
127
        
128
    def test_help_topic(self):
129
        topics = help_topics.HelpTopicRegistry()
130
        topics.register('formats', self.make_format_registry().help_topic, 
131
                        'Directory formats')
132
        topic = topics.get_detail('formats')
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
133
        new, deprecated = topic.split('Deprecated formats')
134
        self.assertContainsRe(new, 'Bazaar directory formats')
135
        self.assertContainsRe(new, 
136
            '  knit/default:\n    \(native\) Format using knits\n')
137
        self.assertContainsRe(deprecated, 
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
138
            '  lazy:\n    \(native\) Format registered lazily\n')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
139
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
140
    def test_set_default_repository(self):
141
        default_factory = bzrdir.format_registry.get('default')
142
        old_default = [k for k, v in bzrdir.format_registry.iteritems()
143
                       if v == default_factory and k != 'default'][0]
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
144
        bzrdir.format_registry.set_default_repository('experimental-knit2')
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
145
        try:
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
146
            self.assertIs(bzrdir.format_registry.get('experimental-knit2'),
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
147
                          bzrdir.format_registry.get('default'))
148
            self.assertIs(
149
                repository.RepositoryFormat.get_default_format().__class__,
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
150
                knitrepo.RepositoryFormatKnit2)
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
151
        finally:
152
            bzrdir.format_registry.set_default_repository(old_default)
153
1508.1.25 by Robert Collins
Update per review comments.
154
class SampleBranch(bzrlib.branch.Branch):
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
155
    """A dummy branch for guess what, dummy use."""
156
157
    def __init__(self, dir):
158
        self.bzrdir = dir
159
160
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
161
class SampleBzrDir(bzrdir.BzrDir):
162
    """A sample BzrDir implementation to allow testing static methods."""
163
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
164
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
165
        """See BzrDir.create_repository."""
166
        return "A repository"
167
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
168
    def open_repository(self):
169
        """See BzrDir.open_repository."""
170
        return "A repository"
171
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
172
    def create_branch(self):
173
        """See BzrDir.create_branch."""
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
174
        return SampleBranch(self)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
175
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
176
    def create_workingtree(self):
177
        """See BzrDir.create_workingtree."""
178
        return "A tree"
179
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
180
1534.4.39 by Robert Collins
Basic BzrDir support.
181
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
182
    """A sample format
183
184
    this format is initializable, unsupported to aid in testing the 
185
    open and open_downlevel routines.
186
    """
187
188
    def get_format_string(self):
189
        """See BzrDirFormat.get_format_string()."""
190
        return "Sample .bzr dir format."
191
192
    def initialize(self, url):
193
        """Create a bzr dir."""
194
        t = get_transport(url)
195
        t.mkdir('.bzr')
1955.3.9 by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes
196
        t.put_bytes('.bzr/branch-format', self.get_format_string())
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
197
        return SampleBzrDir(t, self)
1534.4.39 by Robert Collins
Basic BzrDir support.
198
199
    def is_supported(self):
200
        return False
201
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
202
    def open(self, transport, _found=None):
1534.4.39 by Robert Collins
Basic BzrDir support.
203
        return "opened branch."
204
205
206
class TestBzrDirFormat(TestCaseWithTransport):
207
    """Tests for the BzrDirFormat facility."""
208
209
    def test_find_format(self):
210
        # is the right format object found for a branch?
211
        # create a branch with a few known format objects.
212
        # this is not quite the same as 
213
        t = get_transport(self.get_url())
214
        self.build_tree(["foo/", "bar/"], transport=t)
215
        def check_format(format, url):
216
            format.initialize(url)
217
            t = get_transport(url)
218
            found_format = bzrdir.BzrDirFormat.find_format(t)
219
            self.failUnless(isinstance(found_format, format.__class__))
220
        check_format(bzrdir.BzrDirFormat5(), "foo")
221
        check_format(bzrdir.BzrDirFormat6(), "bar")
222
        
223
    def test_find_format_nothing_there(self):
224
        self.assertRaises(NotBranchError,
225
                          bzrdir.BzrDirFormat.find_format,
226
                          get_transport('.'))
227
228
    def test_find_format_unknown_format(self):
229
        t = get_transport(self.get_url())
230
        t.mkdir('.bzr')
1955.3.13 by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings.
231
        t.put_bytes('.bzr/branch-format', '')
1534.4.39 by Robert Collins
Basic BzrDir support.
232
        self.assertRaises(UnknownFormatError,
233
                          bzrdir.BzrDirFormat.find_format,
234
                          get_transport('.'))
235
236
    def test_register_unregister_format(self):
237
        format = SampleBzrDirFormat()
238
        url = self.get_url()
239
        # make a bzrdir
240
        format.initialize(url)
241
        # register a format for it.
242
        bzrdir.BzrDirFormat.register_format(format)
243
        # which bzrdir.Open will refuse (not supported)
244
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
245
        # which bzrdir.open_containing will refuse (not supported)
246
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
1534.4.39 by Robert Collins
Basic BzrDir support.
247
        # but open_downlevel will work
248
        t = get_transport(url)
249
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
250
        # unregister the format
251
        bzrdir.BzrDirFormat.unregister_format(format)
252
        # now open_downlevel should fail too.
253
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
254
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
255
    def test_create_repository(self):
256
        format = SampleBzrDirFormat()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
257
        repo = bzrdir.BzrDir.create_repository(self.get_url(), format=format)
258
        self.assertEqual('A repository', repo)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
259
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
260
    def test_create_repository_shared(self):
261
        old_format = bzrdir.BzrDirFormat.get_default_format()
262
        repo = bzrdir.BzrDir.create_repository('.', shared=True)
263
        self.assertTrue(repo.is_shared())
264
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
265
    def test_create_repository_nonshared(self):
266
        old_format = bzrdir.BzrDirFormat.get_default_format()
267
        repo = bzrdir.BzrDir.create_repository('.')
268
        self.assertFalse(repo.is_shared())
269
1534.6.10 by Robert Collins
Finish use of repositories support.
270
    def test_create_repository_under_shared(self):
271
        # an explicit create_repository always does so.
272
        # we trust the format is right from the 'create_repository test'
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
273
        format = bzrdir.format_registry.make_bzrdir('knit')
274
        self.make_repository('.', shared=True, format=format)
275
        repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
276
                                               format=format)
277
        self.assertTrue(isinstance(repo, repository.Repository))
278
        self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
1534.6.10 by Robert Collins
Finish use of repositories support.
279
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
280
    def test_create_branch_and_repo_uses_default(self):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
281
        format = SampleBzrDirFormat()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
282
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(), 
283
                                                      format=format)
284
        self.assertTrue(isinstance(branch, SampleBranch))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
285
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
286
    def test_create_branch_and_repo_under_shared(self):
287
        # creating a branch and repo in a shared repo uses the
288
        # shared repository
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
289
        format = bzrdir.format_registry.make_bzrdir('knit')
290
        self.make_repository('.', shared=True, format=format)
291
        branch = bzrdir.BzrDir.create_branch_and_repo(
292
            self.get_url('child'), format=format)
293
        self.assertRaises(errors.NoRepositoryPresent,
294
                          branch.bzrdir.open_repository)
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
295
296
    def test_create_branch_and_repo_under_shared_force_new(self):
297
        # creating a branch and repo in a shared repo can be forced to 
298
        # make a new repo
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
299
        format = bzrdir.format_registry.make_bzrdir('knit')
300
        self.make_repository('.', shared=True, format=format)
301
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
302
                                                      force_new_repo=True,
303
                                                      format=format)
304
        branch.bzrdir.open_repository()
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
305
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
306
    def test_create_standalone_working_tree(self):
307
        format = SampleBzrDirFormat()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
308
        # note this is deliberately readonly, as this failure should 
309
        # occur before any writes.
310
        self.assertRaises(errors.NotLocalUrl,
311
                          bzrdir.BzrDir.create_standalone_workingtree,
312
                          self.get_readonly_url(), format=format)
313
        tree = bzrdir.BzrDir.create_standalone_workingtree('.', 
314
                                                           format=format)
315
        self.assertEqual('A tree', tree)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
316
1534.6.10 by Robert Collins
Finish use of repositories support.
317
    def test_create_standalone_working_tree_under_shared_repo(self):
318
        # create standalone working tree always makes a repo.
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
319
        format = bzrdir.format_registry.make_bzrdir('knit')
320
        self.make_repository('.', shared=True, format=format)
321
        # note this is deliberately readonly, as this failure should 
322
        # occur before any writes.
323
        self.assertRaises(errors.NotLocalUrl,
324
                          bzrdir.BzrDir.create_standalone_workingtree,
325
                          self.get_readonly_url('child'), format=format)
326
        tree = bzrdir.BzrDir.create_standalone_workingtree('child', 
327
            format=format)
328
        tree.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
329
330
    def test_create_branch_convenience(self):
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
331
        # outside a repo the default convenience output is a repo+branch_tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
332
        format = bzrdir.format_registry.make_bzrdir('knit')
333
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
334
        branch.bzrdir.open_workingtree()
335
        branch.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
336
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
337
    def test_create_branch_convenience_root(self):
338
        """Creating a branch at the root of a fs should work."""
339
        self.transport_server = MemoryServer
340
        # outside a repo the default convenience output is a repo+branch_tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
341
        format = bzrdir.format_registry.make_bzrdir('knit')
342
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(), 
343
                                                         format=format)
344
        self.assertRaises(errors.NoWorkingTree,
345
                          branch.bzrdir.open_workingtree)
346
        branch.bzrdir.open_repository()
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
347
1534.6.10 by Robert Collins
Finish use of repositories support.
348
    def test_create_branch_convenience_under_shared_repo(self):
349
        # inside a repo the default convenience output is a branch+ follow the
350
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
351
        format = bzrdir.format_registry.make_bzrdir('knit')
352
        self.make_repository('.', shared=True, format=format)
353
        branch = bzrdir.BzrDir.create_branch_convenience('child',
354
            format=format)
355
        branch.bzrdir.open_workingtree()
356
        self.assertRaises(errors.NoRepositoryPresent,
357
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
358
            
359
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
360
        # inside a repo the default convenience output is a branch+ follow the
361
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
362
        format = bzrdir.format_registry.make_bzrdir('knit')
363
        self.make_repository('.', shared=True, format=format)
364
        branch = bzrdir.BzrDir.create_branch_convenience('child',
365
            force_new_tree=False, format=format)
366
        self.assertRaises(errors.NoWorkingTree,
367
                          branch.bzrdir.open_workingtree)
368
        self.assertRaises(errors.NoRepositoryPresent,
369
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
370
            
371
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
372
        # inside a repo the default convenience output is a branch+ follow the
373
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
374
        format = bzrdir.format_registry.make_bzrdir('knit')
375
        repo = self.make_repository('.', shared=True, format=format)
376
        repo.set_make_working_trees(False)
377
        branch = bzrdir.BzrDir.create_branch_convenience('child', 
378
                                                         format=format)
379
        self.assertRaises(errors.NoWorkingTree,
380
                          branch.bzrdir.open_workingtree)
381
        self.assertRaises(errors.NoRepositoryPresent,
382
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
383
384
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
385
        # inside a repo the default convenience output is a branch+ follow the
386
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
387
        format = bzrdir.format_registry.make_bzrdir('knit')
388
        repo = self.make_repository('.', shared=True, format=format)
389
        repo.set_make_working_trees(False)
390
        branch = bzrdir.BzrDir.create_branch_convenience('child',
391
            force_new_tree=True, format=format)
392
        branch.bzrdir.open_workingtree()
393
        self.assertRaises(errors.NoRepositoryPresent,
394
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
395
396
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
397
        # inside a repo the default convenience output is overridable to give
398
        # repo+branch+tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
399
        format = bzrdir.format_registry.make_bzrdir('knit')
400
        self.make_repository('.', shared=True, format=format)
401
        branch = bzrdir.BzrDir.create_branch_convenience('child',
402
            force_new_repo=True, format=format)
403
        branch.bzrdir.open_repository()
404
        branch.bzrdir.open_workingtree()
1534.6.10 by Robert Collins
Finish use of repositories support.
405
1534.4.39 by Robert Collins
Basic BzrDir support.
406
407
class ChrootedTests(TestCaseWithTransport):
408
    """A support class that provides readonly urls outside the local namespace.
409
410
    This is done by checking if self.transport_server is a MemoryServer. if it
411
    is then we are chrooted already, if it is not then an HttpServer is used
412
    for readonly urls.
413
    """
414
415
    def setUp(self):
416
        super(ChrootedTests, self).setUp()
417
        if not self.transport_server == MemoryServer:
418
            self.transport_readonly_server = HttpServer
419
420
    def test_open_containing(self):
421
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
422
                          self.get_readonly_url(''))
423
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
424
                          self.get_readonly_url('g/p/q'))
425
        control = bzrdir.BzrDir.create(self.get_url())
426
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
427
        self.assertEqual('', relpath)
428
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
429
        self.assertEqual('g/p/q', relpath)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
430
1534.6.11 by Robert Collins
Review feedback.
431
    def test_open_containing_from_transport(self):
432
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
1534.6.3 by Robert Collins
find_repository sufficiently robust.
433
                          get_transport(self.get_readonly_url('')))
1534.6.11 by Robert Collins
Review feedback.
434
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
1534.6.3 by Robert Collins
find_repository sufficiently robust.
435
                          get_transport(self.get_readonly_url('g/p/q')))
436
        control = bzrdir.BzrDir.create(self.get_url())
1534.6.11 by Robert Collins
Review feedback.
437
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
1534.6.3 by Robert Collins
find_repository sufficiently robust.
438
            get_transport(self.get_readonly_url('')))
439
        self.assertEqual('', relpath)
1534.6.11 by Robert Collins
Review feedback.
440
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
1534.6.3 by Robert Collins
find_repository sufficiently robust.
441
            get_transport(self.get_readonly_url('g/p/q')))
442
        self.assertEqual('g/p/q', relpath)
443
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
444
    def test_open_containing_tree_or_branch(self):
445
        def local_branch_path(branch):
2215.3.4 by Aaron Bentley
rewrap some text
446
             return os.path.realpath(
447
                urlutils.local_path_from_url(branch.base))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
448
449
        self.make_branch_and_tree('topdir')
450
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
451
            'topdir/foo')
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
452
        self.assertEqual(os.path.realpath('topdir'),
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
453
                         os.path.realpath(tree.basedir))
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
454
        self.assertEqual(os.path.realpath('topdir'),
2215.3.4 by Aaron Bentley
rewrap some text
455
                         local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
456
        self.assertIs(tree.bzrdir, branch.bzrdir)
457
        self.assertEqual('foo', relpath)
458
        self.make_branch('topdir/foo')
459
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
460
            'topdir/foo')
461
        self.assertIs(tree, None)
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
462
        self.assertEqual(os.path.realpath('topdir/foo'),
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
463
                         local_branch_path(branch))
464
        self.assertEqual('', relpath)
465
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
466
    def test_open_from_transport(self):
467
        # transport pointing at bzrdir should give a bzrdir with root transport
468
        # set to the given transport
469
        control = bzrdir.BzrDir.create(self.get_url())
470
        transport = get_transport(self.get_url())
471
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
472
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
473
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
474
        
475
    def test_open_from_transport_no_bzrdir(self):
476
        transport = get_transport(self.get_url())
477
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
478
                          transport)
479
480
    def test_open_from_transport_bzrdir_in_parent(self):
481
        control = bzrdir.BzrDir.create(self.get_url())
482
        transport = get_transport(self.get_url())
483
        transport.mkdir('subdir')
484
        transport = transport.clone('subdir')
485
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
486
                          transport)
487
2100.3.28 by Aaron Bentley
Make sprout recursive
488
    def test_sprout_recursive(self):
489
        tree = self.make_branch_and_tree('tree1', format='experimental-knit3')
490
        sub_tree = self.make_branch_and_tree('tree1/subtree',
491
                                             format='experimental-knit3')
492
        tree.add_reference(sub_tree)
493
        self.build_tree(['tree1/subtree/file'])
494
        sub_tree.add('file')
495
        tree.commit('Initial commit')
496
        tree.bzrdir.sprout('tree2')
497
        self.failUnlessExists('tree2/subtree/file')
498
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
499
    def test_cloning_metadir(self):
500
        """Ensure that cloning metadir is suitable"""
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
501
        bzrdir = self.make_bzrdir('bzrdir')
502
        bzrdir.cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
503
        branch = self.make_branch('branch', format='knit')
504
        format = branch.bzrdir.cloning_metadir()
505
        self.assertIsInstance(format.workingtree_format,
506
        workingtree.WorkingTreeFormat3)
507
        branch2 = self.make_branch('branch2', format='experimental-knit3')
508
        format2 = branch2.bzrdir.cloning_metadir()
509
        self.assertIsInstance(format2.workingtree_format,
2100.3.37 by Aaron Bentley
rename working tree format 4 to AB1 everywhere
510
                              workingtree.WorkingTreeFormatAB1)
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
511
512
    def test_sprout_recursive_treeless(self):
513
        tree = self.make_branch_and_tree('tree1', format='experimental-knit3')
514
        sub_tree = self.make_branch_and_tree('tree1/subtree',
515
                                             format='experimental-knit3')
516
        tree.add_reference(sub_tree)
517
        self.build_tree(['tree1/subtree/file'])
518
        sub_tree.add('file')
519
        tree.commit('Initial commit')
520
        tree.bzrdir.destroy_workingtree()
521
        repo = self.make_repository('repo', shared=True,
522
                                    format='experimental-knit3')
523
        repo.set_make_working_trees(False)
524
        tree.bzrdir.sprout('repo/tree2')
525
        self.failUnlessExists('repo/tree2/subtree')
526
        self.failIfExists('repo/tree2/subtree/file')
527
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
528
529
class TestMeta1DirFormat(TestCaseWithTransport):
530
    """Tests specific to the meta1 dir format."""
531
532
    def test_right_base_dirs(self):
533
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
534
        t = dir.transport
535
        branch_base = t.clone('branch').base
536
        self.assertEqual(branch_base, dir.get_branch_transport(None).base)
537
        self.assertEqual(branch_base,
1508.1.25 by Robert Collins
Update per review comments.
538
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
539
        repository_base = t.clone('repository').base
540
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
541
        self.assertEqual(repository_base,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
542
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
543
        checkout_base = t.clone('checkout').base
544
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
545
        self.assertEqual(checkout_base,
546
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
547
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
548
    def test_meta1dir_uses_lockdir(self):
549
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
550
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
551
        t = dir.transport
552
        self.assertIsDirectory('branch-lock', t)
553
2100.3.35 by Aaron Bentley
equality operations on bzrdir
554
    def test_comparison(self):
555
        """Equality and inequality behave properly.
556
557
        Metadirs should compare equal iff they have the same repo, branch and
558
        tree formats.
559
        """
560
        mydir = bzrdir.format_registry.make_bzrdir('knit')
561
        self.assertEqual(mydir, mydir)
562
        self.assertFalse(mydir != mydir)
563
        otherdir = bzrdir.format_registry.make_bzrdir('knit')
564
        self.assertEqual(otherdir, mydir)
565
        self.assertFalse(otherdir != mydir)
566
        otherdir2 = bzrdir.format_registry.make_bzrdir('experimental-knit2')
567
        self.assertNotEqual(otherdir2, mydir)
568
        self.assertFalse(otherdir2 == mydir)
569
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
570
        
571
class TestFormat5(TestCaseWithTransport):
572
    """Tests specific to the version 5 bzrdir format."""
573
574
    def test_same_lockfiles_between_tree_repo_branch(self):
575
        # this checks that only a single lockfiles instance is created 
576
        # for format 5 objects
577
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
578
        def check_dir_components_use_same_lock(dir):
579
            ctrl_1 = dir.open_repository().control_files
580
            ctrl_2 = dir.open_branch().control_files
581
            ctrl_3 = dir.open_workingtree()._control_files
582
            self.assertTrue(ctrl_1 is ctrl_2)
583
            self.assertTrue(ctrl_2 is ctrl_3)
584
        check_dir_components_use_same_lock(dir)
585
        # and if we open it normally.
586
        dir = bzrdir.BzrDir.open(self.get_url())
587
        check_dir_components_use_same_lock(dir)
588
    
1534.5.16 by Robert Collins
Review feedback.
589
    def test_can_convert(self):
590
        # format 5 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
591
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
592
        self.assertTrue(dir.can_convert_format())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
593
    
1534.5.16 by Robert Collins
Review feedback.
594
    def test_needs_conversion(self):
595
        # format 5 dirs need a conversion if they are not the default.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
596
        # and they start of not the default.
597
        old_format = bzrdir.BzrDirFormat.get_default_format()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
598
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
599
        try:
600
            dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
601
            self.assertFalse(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
602
        finally:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
603
            bzrdir.BzrDirFormat._set_default_format(old_format)
1534.5.16 by Robert Collins
Review feedback.
604
        self.assertTrue(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
605
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
606
607
class TestFormat6(TestCaseWithTransport):
608
    """Tests specific to the version 6 bzrdir format."""
609
610
    def test_same_lockfiles_between_tree_repo_branch(self):
611
        # this checks that only a single lockfiles instance is created 
612
        # for format 6 objects
613
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
614
        def check_dir_components_use_same_lock(dir):
615
            ctrl_1 = dir.open_repository().control_files
616
            ctrl_2 = dir.open_branch().control_files
617
            ctrl_3 = dir.open_workingtree()._control_files
618
            self.assertTrue(ctrl_1 is ctrl_2)
619
            self.assertTrue(ctrl_2 is ctrl_3)
620
        check_dir_components_use_same_lock(dir)
621
        # and if we open it normally.
622
        dir = bzrdir.BzrDir.open(self.get_url())
623
        check_dir_components_use_same_lock(dir)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
624
    
1534.5.16 by Robert Collins
Review feedback.
625
    def test_can_convert(self):
626
        # format 6 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
627
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
628
        self.assertTrue(dir.can_convert_format())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
629
    
1534.5.16 by Robert Collins
Review feedback.
630
    def test_needs_conversion(self):
631
        # format 6 dirs need an conversion if they are not the default.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
632
        old_format = bzrdir.BzrDirFormat.get_default_format()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
633
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
634
        try:
635
            dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
636
            self.assertTrue(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
637
        finally:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
638
            bzrdir.BzrDirFormat._set_default_format(old_format)
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
639
640
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
641
class NotBzrDir(bzrlib.bzrdir.BzrDir):
642
    """A non .bzr based control directory."""
643
644
    def __init__(self, transport, format):
645
        self._format = format
646
        self.root_transport = transport
647
        self.transport = transport.clone('.not')
648
649
650
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
651
    """A test class representing any non-.bzr based disk format."""
652
653
    def initialize_on_transport(self, transport):
654
        """Initialize a new .not dir in the base directory of a Transport."""
655
        transport.mkdir('.not')
656
        return self.open(transport)
657
658
    def open(self, transport):
659
        """Open this directory."""
660
        return NotBzrDir(transport, self)
661
662
    @classmethod
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
663
    def _known_formats(self):
664
        return set([NotBzrDirFormat()])
665
666
    @classmethod
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
667
    def probe_transport(self, transport):
668
        """Our format is present if the transport ends in '.not/'."""
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
669
        if transport.has('.not'):
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
670
            return NotBzrDirFormat()
671
672
673
class TestNotBzrDir(TestCaseWithTransport):
674
    """Tests for using the bzrdir api with a non .bzr based disk format.
675
    
676
    If/when one of these is in the core, we can let the implementation tests
677
    verify this works.
678
    """
679
680
    def test_create_and_find_format(self):
681
        # create a .notbzr dir 
682
        format = NotBzrDirFormat()
683
        dir = format.initialize(self.get_url())
684
        self.assertIsInstance(dir, NotBzrDir)
685
        # now probe for it.
686
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
687
        try:
688
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
689
                get_transport(self.get_url()))
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
690
            self.assertIsInstance(found, NotBzrDirFormat)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
691
        finally:
692
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
693
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
694
    def test_included_in_known_formats(self):
695
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
696
        try:
697
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
698
            for format in formats:
699
                if isinstance(format, NotBzrDirFormat):
700
                    return
701
            self.fail("No NotBzrDirFormat in %s" % formats)
702
        finally:
703
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
704
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
705
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
706
class NonLocalTests(TestCaseWithTransport):
707
    """Tests for bzrdir static behaviour on non local paths."""
708
709
    def setUp(self):
710
        super(NonLocalTests, self).setUp()
711
        self.transport_server = MemoryServer
712
    
713
    def test_create_branch_convenience(self):
714
        # outside a repo the default convenience output is a repo+branch_tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
715
        format = bzrdir.format_registry.make_bzrdir('knit')
716
        branch = bzrdir.BzrDir.create_branch_convenience(
717
            self.get_url('foo'), format=format)
718
        self.assertRaises(errors.NoWorkingTree,
719
                          branch.bzrdir.open_workingtree)
720
        branch.bzrdir.open_repository()
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
721
722
    def test_create_branch_convenience_force_tree_not_local_fails(self):
723
        # outside a repo the default convenience output is a repo+branch_tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
724
        format = bzrdir.format_registry.make_bzrdir('knit')
725
        self.assertRaises(errors.NotLocalUrl,
726
            bzrdir.BzrDir.create_branch_convenience,
727
            self.get_url('foo'),
728
            force_new_tree=True,
729
            format=format)
730
        t = get_transport(self.get_url('.'))
731
        self.assertFalse(t.has('foo'))
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
732
1563.2.38 by Robert Collins
make push preserve tree formats.
733
    def test_clone(self):
734
        # clone into a nonlocal path works
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
735
        format = bzrdir.format_registry.make_bzrdir('knit')
736
        branch = bzrdir.BzrDir.create_branch_convenience('local',
737
                                                         format=format)
1563.2.38 by Robert Collins
make push preserve tree formats.
738
        branch.bzrdir.open_workingtree()
739
        result = branch.bzrdir.clone(self.get_url('remote'))
740
        self.assertRaises(errors.NoWorkingTree,
741
                          result.open_workingtree)
742
        result.open_branch()
743
        result.open_repository()
744
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
745
    def test_checkout_metadir(self):
746
        # checkout_metadir has reasonable working tree format even when no
747
        # working tree is present
748
        self.make_branch('branch-knit3', format='experimental-knit3')
749
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit3'))
750
        checkout_format = my_bzrdir.checkout_metadir()
751
        self.assertIsInstance(checkout_format.workingtree_format,
2100.3.37 by Aaron Bentley
rename working tree format 4 to AB1 everywhere
752
                              workingtree.WorkingTreeFormatAB1)
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
753
754
        self.make_branch('branch-knit2', format='experimental-knit2')
755
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
756
        checkout_format = my_bzrdir.checkout_metadir()
757
        self.assertIsInstance(checkout_format.workingtree_format,
758
                              workingtree.WorkingTreeFormat3)
2100.3.22 by Aaron Bentley
merge from bzr.dev
759
2215.3.5 by Aaron Bentley
Add support for remote ls
760
761
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):
762
763
    def test_open_containing_tree_or_branch(self):
764
        tree = self.make_branch_and_tree('tree')
765
        bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))