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