~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-11 10:05:33 UTC
  • mfrom: (1185.50.95 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060511100533-e3d066b362716fe2
(jam) update web page url to http://bazaar-vcs.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
 
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.
 
7
 
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.
 
12
 
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
 
 
22
from StringIO import StringIO
 
23
 
 
24
import bzrlib.branch
 
25
import bzrlib.bzrdir as bzrdir
 
26
import bzrlib.errors as errors
 
27
from bzrlib.errors import (NotBranchError,
 
28
                           UnknownFormatError,
 
29
                           UnsupportedFormatError,
 
30
                           )
 
31
import bzrlib.repository as repository
 
32
from bzrlib.tests import TestCase, TestCaseWithTransport
 
33
from bzrlib.transport import get_transport
 
34
from bzrlib.transport.http import HttpServer
 
35
from bzrlib.transport.memory import MemoryServer
 
36
import bzrlib.workingtree as workingtree
 
37
 
 
38
 
 
39
class TestDefaultFormat(TestCase):
 
40
 
 
41
    def test_get_set_default_format(self):
 
42
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
43
        # default is BzrDirFormat6
 
44
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
 
45
        bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
 
46
        # creating a bzr dir should now create an instrumented dir.
 
47
        try:
 
48
            result = bzrdir.BzrDir.create('memory:/')
 
49
            self.failUnless(isinstance(result, SampleBzrDir))
 
50
        finally:
 
51
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
52
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
 
53
 
 
54
 
 
55
class SampleBranch(bzrlib.branch.Branch):
 
56
    """A dummy branch for guess what, dummy use."""
 
57
 
 
58
    def __init__(self, dir):
 
59
        self.bzrdir = dir
 
60
 
 
61
 
 
62
class SampleBzrDir(bzrdir.BzrDir):
 
63
    """A sample BzrDir implementation to allow testing static methods."""
 
64
 
 
65
    def create_repository(self):
 
66
        """See BzrDir.create_repository."""
 
67
        return "A repository"
 
68
 
 
69
    def open_repository(self):
 
70
        """See BzrDir.open_repository."""
 
71
        return "A repository"
 
72
 
 
73
    def create_branch(self):
 
74
        """See BzrDir.create_branch."""
 
75
        return SampleBranch(self)
 
76
 
 
77
    def create_workingtree(self):
 
78
        """See BzrDir.create_workingtree."""
 
79
        return "A tree"
 
80
 
 
81
 
 
82
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
 
83
    """A sample format
 
84
 
 
85
    this format is initializable, unsupported to aid in testing the 
 
86
    open and open_downlevel routines.
 
87
    """
 
88
 
 
89
    def get_format_string(self):
 
90
        """See BzrDirFormat.get_format_string()."""
 
91
        return "Sample .bzr dir format."
 
92
 
 
93
    def initialize(self, url):
 
94
        """Create a bzr dir."""
 
95
        t = get_transport(url)
 
96
        t.mkdir('.bzr')
 
97
        t.put('.bzr/branch-format', StringIO(self.get_format_string()))
 
98
        return SampleBzrDir(t, self)
 
99
 
 
100
    def is_supported(self):
 
101
        return False
 
102
 
 
103
    def open(self, transport, _found=None):
 
104
        return "opened branch."
 
105
 
 
106
 
 
107
class TestBzrDirFormat(TestCaseWithTransport):
 
108
    """Tests for the BzrDirFormat facility."""
 
109
 
 
110
    def test_find_format(self):
 
111
        # is the right format object found for a branch?
 
112
        # create a branch with a few known format objects.
 
113
        # this is not quite the same as 
 
114
        t = get_transport(self.get_url())
 
115
        self.build_tree(["foo/", "bar/"], transport=t)
 
116
        def check_format(format, url):
 
117
            format.initialize(url)
 
118
            t = get_transport(url)
 
119
            found_format = bzrdir.BzrDirFormat.find_format(t)
 
120
            self.failUnless(isinstance(found_format, format.__class__))
 
121
        check_format(bzrdir.BzrDirFormat5(), "foo")
 
122
        check_format(bzrdir.BzrDirFormat6(), "bar")
 
123
        
 
124
    def test_find_format_nothing_there(self):
 
125
        self.assertRaises(NotBranchError,
 
126
                          bzrdir.BzrDirFormat.find_format,
 
127
                          get_transport('.'))
 
128
 
 
129
    def test_find_format_unknown_format(self):
 
130
        t = get_transport(self.get_url())
 
131
        t.mkdir('.bzr')
 
132
        t.put('.bzr/branch-format', StringIO())
 
133
        self.assertRaises(UnknownFormatError,
 
134
                          bzrdir.BzrDirFormat.find_format,
 
135
                          get_transport('.'))
 
136
 
 
137
    def test_register_unregister_format(self):
 
138
        format = SampleBzrDirFormat()
 
139
        url = self.get_url()
 
140
        # make a bzrdir
 
141
        format.initialize(url)
 
142
        # register a format for it.
 
143
        bzrdir.BzrDirFormat.register_format(format)
 
144
        # which bzrdir.Open will refuse (not supported)
 
145
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
 
146
        # which bzrdir.open_containing will refuse (not supported)
 
147
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
 
148
        # but open_downlevel will work
 
149
        t = get_transport(url)
 
150
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
 
151
        # unregister the format
 
152
        bzrdir.BzrDirFormat.unregister_format(format)
 
153
        # now open_downlevel should fail too.
 
154
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
 
155
 
 
156
    def test_create_repository(self):
 
157
        format = SampleBzrDirFormat()
 
158
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
159
        bzrdir.BzrDirFormat.set_default_format(format)
 
160
        try:
 
161
            repo = bzrdir.BzrDir.create_repository(self.get_url())
 
162
            self.assertEqual('A repository', repo)
 
163
        finally:
 
164
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
165
 
 
166
    def test_create_repository_under_shared(self):
 
167
        # an explicit create_repository always does so.
 
168
        # we trust the format is right from the 'create_repository test'
 
169
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
170
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
171
        try:
 
172
            self.make_repository('.', shared=True)
 
173
            repo = bzrdir.BzrDir.create_repository(self.get_url('child'))
 
174
            self.assertTrue(isinstance(repo, repository.Repository))
 
175
            self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
 
176
        finally:
 
177
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
178
 
 
179
    def test_create_branch_and_repo_uses_default(self):
 
180
        format = SampleBzrDirFormat()
 
181
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
182
        bzrdir.BzrDirFormat.set_default_format(format)
 
183
        try:
 
184
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url())
 
185
            self.assertTrue(isinstance(branch, SampleBranch))
 
186
        finally:
 
187
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
188
 
 
189
    def test_create_branch_and_repo_under_shared(self):
 
190
        # creating a branch and repo in a shared repo uses the
 
191
        # shared repository
 
192
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
193
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
194
        try:
 
195
            self.make_repository('.', shared=True)
 
196
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'))
 
197
            self.assertRaises(errors.NoRepositoryPresent,
 
198
                              branch.bzrdir.open_repository)
 
199
        finally:
 
200
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
201
 
 
202
    def test_create_branch_and_repo_under_shared_force_new(self):
 
203
        # creating a branch and repo in a shared repo can be forced to 
 
204
        # make a new repo
 
205
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
206
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
207
        try:
 
208
            self.make_repository('.', shared=True)
 
209
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
 
210
                                                          force_new_repo=True)
 
211
            branch.bzrdir.open_repository()
 
212
        finally:
 
213
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
214
 
 
215
    def test_create_standalone_working_tree(self):
 
216
        format = SampleBzrDirFormat()
 
217
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
218
        bzrdir.BzrDirFormat.set_default_format(format)
 
219
        try:
 
220
            # note this is deliberately readonly, as this failure should 
 
221
            # occur before any writes.
 
222
            self.assertRaises(errors.NotLocalUrl,
 
223
                              bzrdir.BzrDir.create_standalone_workingtree,
 
224
                              self.get_readonly_url())
 
225
            tree = bzrdir.BzrDir.create_standalone_workingtree('.')
 
226
            self.assertEqual('A tree', tree)
 
227
        finally:
 
228
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
229
 
 
230
    def test_create_standalone_working_tree_under_shared_repo(self):
 
231
        # create standalone working tree always makes a repo.
 
232
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
233
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
234
        try:
 
235
            self.make_repository('.', shared=True)
 
236
            # note this is deliberately readonly, as this failure should 
 
237
            # occur before any writes.
 
238
            self.assertRaises(errors.NotLocalUrl,
 
239
                              bzrdir.BzrDir.create_standalone_workingtree,
 
240
                              self.get_readonly_url('child'))
 
241
            tree = bzrdir.BzrDir.create_standalone_workingtree('child')
 
242
            tree.bzrdir.open_repository()
 
243
        finally:
 
244
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
245
 
 
246
    def test_create_branch_convenience(self):
 
247
        # outside a repo the default convenience output is a repo+branch_tree
 
248
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
249
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
250
        try:
 
251
            branch = bzrdir.BzrDir.create_branch_convenience('.')
 
252
            branch.bzrdir.open_workingtree()
 
253
            branch.bzrdir.open_repository()
 
254
        finally:
 
255
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
256
 
 
257
    def test_create_branch_convenience_under_shared_repo(self):
 
258
        # inside a repo the default convenience output is a branch+ follow the
 
259
        # repo tree policy
 
260
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
261
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
262
        try:
 
263
            self.make_repository('.', shared=True)
 
264
            branch = bzrdir.BzrDir.create_branch_convenience('child')
 
265
            branch.bzrdir.open_workingtree()
 
266
            self.assertRaises(errors.NoRepositoryPresent,
 
267
                              branch.bzrdir.open_repository)
 
268
        finally:
 
269
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
270
            
 
271
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
 
272
        # inside a repo the default convenience output is a branch+ follow the
 
273
        # repo tree policy but we can override that
 
274
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
275
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
276
        try:
 
277
            self.make_repository('.', shared=True)
 
278
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
279
                force_new_tree=False)
 
280
            self.assertRaises(errors.NoWorkingTree,
 
281
                              branch.bzrdir.open_workingtree)
 
282
            self.assertRaises(errors.NoRepositoryPresent,
 
283
                              branch.bzrdir.open_repository)
 
284
        finally:
 
285
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
286
            
 
287
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
 
288
        # inside a repo the default convenience output is a branch+ follow the
 
289
        # repo tree policy
 
290
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
291
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
292
        try:
 
293
            repo = self.make_repository('.', shared=True)
 
294
            repo.set_make_working_trees(False)
 
295
            branch = bzrdir.BzrDir.create_branch_convenience('child')
 
296
            self.assertRaises(errors.NoWorkingTree,
 
297
                              branch.bzrdir.open_workingtree)
 
298
            self.assertRaises(errors.NoRepositoryPresent,
 
299
                              branch.bzrdir.open_repository)
 
300
        finally:
 
301
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
302
 
 
303
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
 
304
        # inside a repo the default convenience output is a branch+ follow the
 
305
        # repo tree policy but we can override that
 
306
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
307
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
308
        try:
 
309
            repo = self.make_repository('.', shared=True)
 
310
            repo.set_make_working_trees(False)
 
311
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
312
                force_new_tree=True)
 
313
            branch.bzrdir.open_workingtree()
 
314
            self.assertRaises(errors.NoRepositoryPresent,
 
315
                              branch.bzrdir.open_repository)
 
316
        finally:
 
317
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
318
 
 
319
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
 
320
        # inside a repo the default convenience output is overridable to give
 
321
        # repo+branch+tree
 
322
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
323
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
324
        try:
 
325
            self.make_repository('.', shared=True)
 
326
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
327
                force_new_repo=True)
 
328
            branch.bzrdir.open_repository()
 
329
            branch.bzrdir.open_workingtree()
 
330
        finally:
 
331
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
332
 
 
333
 
 
334
class ChrootedTests(TestCaseWithTransport):
 
335
    """A support class that provides readonly urls outside the local namespace.
 
336
 
 
337
    This is done by checking if self.transport_server is a MemoryServer. if it
 
338
    is then we are chrooted already, if it is not then an HttpServer is used
 
339
    for readonly urls.
 
340
    """
 
341
 
 
342
    def setUp(self):
 
343
        super(ChrootedTests, self).setUp()
 
344
        if not self.transport_server == MemoryServer:
 
345
            self.transport_readonly_server = HttpServer
 
346
 
 
347
    def test_open_containing(self):
 
348
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
 
349
                          self.get_readonly_url(''))
 
350
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
 
351
                          self.get_readonly_url('g/p/q'))
 
352
        control = bzrdir.BzrDir.create(self.get_url())
 
353
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
 
354
        self.assertEqual('', relpath)
 
355
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
 
356
        self.assertEqual('g/p/q', relpath)
 
357
 
 
358
    def test_open_containing_from_transport(self):
 
359
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
360
                          get_transport(self.get_readonly_url('')))
 
361
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
 
362
                          get_transport(self.get_readonly_url('g/p/q')))
 
363
        control = bzrdir.BzrDir.create(self.get_url())
 
364
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
 
365
            get_transport(self.get_readonly_url('')))
 
366
        self.assertEqual('', relpath)
 
367
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
 
368
            get_transport(self.get_readonly_url('g/p/q')))
 
369
        self.assertEqual('g/p/q', relpath)
 
370
 
 
371
 
 
372
class TestMeta1DirFormat(TestCaseWithTransport):
 
373
    """Tests specific to the meta1 dir format."""
 
374
 
 
375
    def test_right_base_dirs(self):
 
376
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
377
        t = dir.transport
 
378
        branch_base = t.clone('branch').base
 
379
        self.assertEqual(branch_base, dir.get_branch_transport(None).base)
 
380
        self.assertEqual(branch_base,
 
381
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
 
382
        repository_base = t.clone('repository').base
 
383
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
 
384
        self.assertEqual(repository_base,
 
385
                         dir.get_repository_transport(repository.RepositoryFormat7()).base)
 
386
        checkout_base = t.clone('checkout').base
 
387
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
 
388
        self.assertEqual(checkout_base,
 
389
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
 
390
 
 
391
    def test_meta1dir_uses_lockdir(self):
 
392
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
 
393
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
394
        t = dir.transport
 
395
        self.assertIsDirectory('branch-lock', t)
 
396
 
 
397
        
 
398
class TestFormat5(TestCaseWithTransport):
 
399
    """Tests specific to the version 5 bzrdir format."""
 
400
 
 
401
    def test_same_lockfiles_between_tree_repo_branch(self):
 
402
        # this checks that only a single lockfiles instance is created 
 
403
        # for format 5 objects
 
404
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
405
        def check_dir_components_use_same_lock(dir):
 
406
            ctrl_1 = dir.open_repository().control_files
 
407
            ctrl_2 = dir.open_branch().control_files
 
408
            ctrl_3 = dir.open_workingtree()._control_files
 
409
            self.assertTrue(ctrl_1 is ctrl_2)
 
410
            self.assertTrue(ctrl_2 is ctrl_3)
 
411
        check_dir_components_use_same_lock(dir)
 
412
        # and if we open it normally.
 
413
        dir = bzrdir.BzrDir.open(self.get_url())
 
414
        check_dir_components_use_same_lock(dir)
 
415
    
 
416
    def test_can_convert(self):
 
417
        # format 5 dirs are convertable
 
418
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
419
        self.assertTrue(dir.can_convert_format())
 
420
    
 
421
    def test_needs_conversion(self):
 
422
        # format 5 dirs need a conversion if they are not the default.
 
423
        # and they start of not the default.
 
424
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
425
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
426
        try:
 
427
            dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
 
428
            self.assertFalse(dir.needs_format_conversion())
 
429
        finally:
 
430
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
431
        self.assertTrue(dir.needs_format_conversion())
 
432
 
 
433
 
 
434
class TestFormat6(TestCaseWithTransport):
 
435
    """Tests specific to the version 6 bzrdir format."""
 
436
 
 
437
    def test_same_lockfiles_between_tree_repo_branch(self):
 
438
        # this checks that only a single lockfiles instance is created 
 
439
        # for format 6 objects
 
440
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
441
        def check_dir_components_use_same_lock(dir):
 
442
            ctrl_1 = dir.open_repository().control_files
 
443
            ctrl_2 = dir.open_branch().control_files
 
444
            ctrl_3 = dir.open_workingtree()._control_files
 
445
            self.assertTrue(ctrl_1 is ctrl_2)
 
446
            self.assertTrue(ctrl_2 is ctrl_3)
 
447
        check_dir_components_use_same_lock(dir)
 
448
        # and if we open it normally.
 
449
        dir = bzrdir.BzrDir.open(self.get_url())
 
450
        check_dir_components_use_same_lock(dir)
 
451
    
 
452
    def test_can_convert(self):
 
453
        # format 6 dirs are convertable
 
454
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
455
        self.assertTrue(dir.can_convert_format())
 
456
    
 
457
    def test_needs_conversion(self):
 
458
        # format 6 dirs need an conversion if they are not the default.
 
459
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
460
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
461
        try:
 
462
            dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
 
463
            self.assertTrue(dir.needs_format_conversion())
 
464
        finally:
 
465
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
466
 
 
467
 
 
468
class NonLocalTests(TestCaseWithTransport):
 
469
    """Tests for bzrdir static behaviour on non local paths."""
 
470
 
 
471
    def setUp(self):
 
472
        super(NonLocalTests, self).setUp()
 
473
        self.transport_server = MemoryServer
 
474
    
 
475
    def test_create_branch_convenience(self):
 
476
        # outside a repo the default convenience output is a repo+branch_tree
 
477
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
478
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
479
        try:
 
480
            branch = bzrdir.BzrDir.create_branch_convenience(self.get_url('foo'))
 
481
            self.assertRaises(errors.NoWorkingTree,
 
482
                              branch.bzrdir.open_workingtree)
 
483
            branch.bzrdir.open_repository()
 
484
        finally:
 
485
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
486
 
 
487
    def test_create_branch_convenience_force_tree_not_local_fails(self):
 
488
        # outside a repo the default convenience output is a repo+branch_tree
 
489
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
490
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
491
        try:
 
492
            self.assertRaises(errors.NotLocalUrl,
 
493
                bzrdir.BzrDir.create_branch_convenience,
 
494
                self.get_url('foo'),
 
495
                force_new_tree=True)
 
496
            t = get_transport(self.get_url('.'))
 
497
            self.assertFalse(t.has('foo'))
 
498
        finally:
 
499
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
500
 
 
501
    def test_clone(self):
 
502
        # clone into a nonlocal path works
 
503
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
504
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
505
        try:
 
506
            branch = bzrdir.BzrDir.create_branch_convenience('local')
 
507
        finally:
 
508
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
509
        branch.bzrdir.open_workingtree()
 
510
        result = branch.bzrdir.clone(self.get_url('remote'))
 
511
        self.assertRaises(errors.NoWorkingTree,
 
512
                          result.open_workingtree)
 
513
        result.open_branch()
 
514
        result.open_repository()
 
515