/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2696.3.1 by Martin Pool
(broken) start switching format to dirstate-tags
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
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
22
import os
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
23
import os.path
1534.4.39 by Robert Collins
Basic BzrDir support.
24
from StringIO import StringIO
3023.1.3 by Alexander Belchenko
John's review
25
import subprocess
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
26
import sys
1534.4.39 by Robert Collins
Basic BzrDir support.
27
2204.4.1 by Aaron Bentley
Add 'formats' help topic
28
from bzrlib import (
2100.3.35 by Aaron Bentley
equality operations on bzrdir
29
    bzrdir,
30
    errors,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
31
    help_topics,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
32
    repository,
2204.4.12 by Aaron Bentley
Deprecate bzrdir.BzrDirFormat.set_default_format
33
    symbol_versioning,
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
34
    urlutils,
3023.1.2 by Alexander Belchenko
Martin's review.
35
    win32utils,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
36
    workingtree,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
37
    )
1508.1.25 by Robert Collins
Update per review comments.
38
import bzrlib.branch
1534.4.39 by Robert Collins
Basic BzrDir support.
39
from bzrlib.errors import (NotBranchError,
40
                           UnknownFormatError,
41
                           UnsupportedFormatError,
42
                           )
2164.2.16 by Vincent Ladeuil
Add tests.
43
from bzrlib.tests import (
44
    TestCase,
45
    TestCaseWithTransport,
3023.1.2 by Alexander Belchenko
Martin's review.
46
    TestSkipped,
2164.2.16 by Vincent Ladeuil
Add tests.
47
    test_sftp_transport
48
    )
3102.1.1 by Vincent Ladeuil
Rename bzrlib/test/HTTPTestUtils.py to bzrlib/tests/http_utils.py and fix
49
from bzrlib.tests.http_server import HttpServer
50
from bzrlib.tests.http_utils import (
2164.2.16 by Vincent Ladeuil
Add tests.
51
    TestCaseWithTwoWebservers,
52
    HTTPServerRedirecting,
53
    )
54
from bzrlib.tests.test_http import TestWithTransport_pycurl
1534.4.39 by Robert Collins
Basic BzrDir support.
55
from bzrlib.transport import get_transport
2164.2.16 by Vincent Ladeuil
Add tests.
56
from bzrlib.transport.http._urllib import HttpTransport_urllib
1534.4.39 by Robert Collins
Basic BzrDir support.
57
from bzrlib.transport.memory import MemoryServer
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
58
from bzrlib.repofmt import knitrepo, weaverepo
1534.4.39 by Robert Collins
Basic BzrDir support.
59
60
61
class TestDefaultFormat(TestCase):
62
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
63
    def test_get_set_default_format(self):
1534.4.39 by Robert Collins
Basic BzrDir support.
64
        old_format = bzrdir.BzrDirFormat.get_default_format()
65
        # default is BzrDirFormat6
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
66
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
3400.3.6 by Martin Pool
Remove code deprecated prior to 1.1 and its tests
67
        bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
1534.4.39 by Robert Collins
Basic BzrDir support.
68
        # creating a bzr dir should now create an instrumented dir.
69
        try:
1685.1.42 by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly.
70
            result = bzrdir.BzrDir.create('memory:///')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
71
            self.failUnless(isinstance(result, SampleBzrDir))
1534.4.39 by Robert Collins
Basic BzrDir support.
72
        finally:
3400.3.6 by Martin Pool
Remove code deprecated prior to 1.1 and its tests
73
            bzrdir.BzrDirFormat._set_default_format(old_format)
1534.4.39 by Robert Collins
Basic BzrDir support.
74
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
75
76
2204.4.1 by Aaron Bentley
Add 'formats' help topic
77
class TestFormatRegistry(TestCase):
78
79
    def make_format_registry(self):
80
        my_format_registry = bzrdir.BzrDirFormatRegistry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
81
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
82
            '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
83
            ' repositories', deprecated=True)
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
84
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir', 
85
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
86
        my_format_registry.register_metadir('knit',
87
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
88
            'Format using knits',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
89
            )
2204.4.1 by Aaron Bentley
Add 'formats' help topic
90
        my_format_registry.set_default('knit')
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
91
        my_format_registry.register_metadir(
2230.3.53 by Aaron Bentley
Merge bzr.dev
92
            'branch6',
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
93
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2230.3.53 by Aaron Bentley
Merge bzr.dev
94
            'Experimental successor to knit.  Use at your own risk.',
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
95
            branch_format='bzrlib.branch.BzrBranchFormat6',
96
            experimental=True)
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
97
        my_format_registry.register_metadir(
98
            'hidden format',
99
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
100
            'Experimental successor to knit.  Use at your own risk.',
101
            branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
102
        my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
103
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
104
            ' repositories', hidden=True)
105
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
106
            'BzrDirFormat6', 'Format registered lazily', deprecated=True,
107
            hidden=True)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
108
        return my_format_registry
109
110
    def test_format_registry(self):
111
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
112
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
113
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
114
        my_bzrdir = my_format_registry.make_bzrdir('weave')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
115
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
116
        my_bzrdir = my_format_registry.make_bzrdir('default')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
117
        self.assertIsInstance(my_bzrdir.repository_format, 
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
118
            knitrepo.RepositoryFormatKnit1)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
119
        my_bzrdir = my_format_registry.make_bzrdir('knit')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
120
        self.assertIsInstance(my_bzrdir.repository_format, 
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
121
            knitrepo.RepositoryFormatKnit1)
2230.3.1 by Aaron Bentley
Get branch6 creation working
122
        my_bzrdir = my_format_registry.make_bzrdir('branch6')
2230.3.55 by Aaron Bentley
Updates from review
123
        self.assertIsInstance(my_bzrdir.get_branch_format(),
2230.3.1 by Aaron Bentley
Get branch6 creation working
124
                              bzrlib.branch.BzrBranchFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
125
126
    def test_get_help(self):
127
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
128
        self.assertEqual('Format registered lazily',
129
                         my_format_registry.get_help('lazy'))
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
130
        self.assertEqual('Format using knits', 
2204.4.1 by Aaron Bentley
Add 'formats' help topic
131
                         my_format_registry.get_help('knit'))
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
132
        self.assertEqual('Format using knits', 
2204.4.1 by Aaron Bentley
Add 'formats' help topic
133
                         my_format_registry.get_help('default'))
134
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
135
                         ' checkouts or shared repositories', 
136
                         my_format_registry.get_help('weave'))
137
        
138
    def test_help_topic(self):
139
        topics = help_topics.HelpTopicRegistry()
140
        topics.register('formats', self.make_format_registry().help_topic, 
141
                        'Directory formats')
142
        topic = topics.get_detail('formats')
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
143
        new, rest = topic.split('Experimental formats')
144
        experimental, deprecated = rest.split('Deprecated formats')
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
145
        self.assertContainsRe(new, 'These formats can be used')
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
146
        self.assertContainsRe(new, 
2666.1.8 by Ian Clatworthy
Fix storage formats help test
147
                ':knit:\n    \(native\) \(default\) Format using knits\n')
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
148
        self.assertContainsRe(experimental, 
149
                ':branch6:\n    \(native\) Experimental successor to knit')
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
150
        self.assertContainsRe(deprecated, 
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
151
                ':lazy:\n    \(native\) Format registered lazily\n')
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
152
        self.assertNotContainsRe(new, 'hidden')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
153
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
154
    def test_set_default_repository(self):
155
        default_factory = bzrdir.format_registry.get('default')
156
        old_default = [k for k, v in bzrdir.format_registry.iteritems()
157
                       if v == default_factory and k != 'default'][0]
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
158
        bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
159
        try:
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
160
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
161
                          bzrdir.format_registry.get('default'))
162
            self.assertIs(
163
                repository.RepositoryFormat.get_default_format().__class__,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
164
                knitrepo.RepositoryFormatKnit3)
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
165
        finally:
166
            bzrdir.format_registry.set_default_repository(old_default)
167
3152.2.2 by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to
168
    def test_aliases(self):
169
        a_registry = bzrdir.BzrDirFormatRegistry()
170
        a_registry.register('weave', bzrdir.BzrDirFormat6,
171
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
172
            ' repositories', deprecated=True)
173
        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
174
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
175
            ' repositories', deprecated=True, alias=True)
176
        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
177
    
2220.2.25 by Martin Pool
doc
178
1508.1.25 by Robert Collins
Update per review comments.
179
class SampleBranch(bzrlib.branch.Branch):
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
180
    """A dummy branch for guess what, dummy use."""
181
182
    def __init__(self, dir):
183
        self.bzrdir = dir
184
185
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
186
class SampleBzrDir(bzrdir.BzrDir):
187
    """A sample BzrDir implementation to allow testing static methods."""
188
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
189
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
190
        """See BzrDir.create_repository."""
191
        return "A repository"
192
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.
193
    def open_repository(self):
194
        """See BzrDir.open_repository."""
195
        return "A repository"
196
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
197
    def create_branch(self):
198
        """See BzrDir.create_branch."""
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
199
        return SampleBranch(self)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
200
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
201
    def create_workingtree(self):
202
        """See BzrDir.create_workingtree."""
203
        return "A tree"
204
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
205
1534.4.39 by Robert Collins
Basic BzrDir support.
206
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
207
    """A sample format
208
209
    this format is initializable, unsupported to aid in testing the 
210
    open and open_downlevel routines.
211
    """
212
213
    def get_format_string(self):
214
        """See BzrDirFormat.get_format_string()."""
215
        return "Sample .bzr dir format."
216
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
217
    def initialize_on_transport(self, t):
1534.4.39 by Robert Collins
Basic BzrDir support.
218
        """Create a bzr dir."""
219
        t.mkdir('.bzr')
1955.3.9 by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes
220
        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.
221
        return SampleBzrDir(t, self)
1534.4.39 by Robert Collins
Basic BzrDir support.
222
223
    def is_supported(self):
224
        return False
225
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
226
    def open(self, transport, _found=None):
1534.4.39 by Robert Collins
Basic BzrDir support.
227
        return "opened branch."
228
229
230
class TestBzrDirFormat(TestCaseWithTransport):
231
    """Tests for the BzrDirFormat facility."""
232
233
    def test_find_format(self):
234
        # is the right format object found for a branch?
235
        # create a branch with a few known format objects.
236
        # this is not quite the same as 
237
        t = get_transport(self.get_url())
238
        self.build_tree(["foo/", "bar/"], transport=t)
239
        def check_format(format, url):
240
            format.initialize(url)
241
            t = get_transport(url)
242
            found_format = bzrdir.BzrDirFormat.find_format(t)
243
            self.failUnless(isinstance(found_format, format.__class__))
244
        check_format(bzrdir.BzrDirFormat5(), "foo")
245
        check_format(bzrdir.BzrDirFormat6(), "bar")
246
        
247
    def test_find_format_nothing_there(self):
248
        self.assertRaises(NotBranchError,
249
                          bzrdir.BzrDirFormat.find_format,
250
                          get_transport('.'))
251
252
    def test_find_format_unknown_format(self):
253
        t = get_transport(self.get_url())
254
        t.mkdir('.bzr')
1955.3.13 by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings.
255
        t.put_bytes('.bzr/branch-format', '')
1534.4.39 by Robert Collins
Basic BzrDir support.
256
        self.assertRaises(UnknownFormatError,
257
                          bzrdir.BzrDirFormat.find_format,
258
                          get_transport('.'))
259
260
    def test_register_unregister_format(self):
261
        format = SampleBzrDirFormat()
262
        url = self.get_url()
263
        # make a bzrdir
264
        format.initialize(url)
265
        # register a format for it.
266
        bzrdir.BzrDirFormat.register_format(format)
267
        # which bzrdir.Open will refuse (not supported)
268
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
269
        # which bzrdir.open_containing will refuse (not supported)
270
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
1534.4.39 by Robert Collins
Basic BzrDir support.
271
        # but open_downlevel will work
272
        t = get_transport(url)
273
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
274
        # unregister the format
275
        bzrdir.BzrDirFormat.unregister_format(format)
276
        # now open_downlevel should fail too.
277
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
278
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.
279
    def test_create_branch_and_repo_uses_default(self):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
280
        format = SampleBzrDirFormat()
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
281
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
282
                                                      format=format)
283
        self.assertTrue(isinstance(branch, SampleBranch))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
284
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.
285
    def test_create_branch_and_repo_under_shared(self):
286
        # creating a branch and repo in a shared repo uses the
287
        # shared repository
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
288
        format = bzrdir.format_registry.make_bzrdir('knit')
289
        self.make_repository('.', shared=True, format=format)
290
        branch = bzrdir.BzrDir.create_branch_and_repo(
291
            self.get_url('child'), format=format)
292
        self.assertRaises(errors.NoRepositoryPresent,
293
                          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.
294
295
    def test_create_branch_and_repo_under_shared_force_new(self):
296
        # creating a branch and repo in a shared repo can be forced to 
297
        # make a new repo
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
298
        format = bzrdir.format_registry.make_bzrdir('knit')
299
        self.make_repository('.', shared=True, format=format)
300
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
301
                                                      force_new_repo=True,
302
                                                      format=format)
303
        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.
304
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
305
    def test_create_standalone_working_tree(self):
306
        format = SampleBzrDirFormat()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
307
        # note this is deliberately readonly, as this failure should 
308
        # occur before any writes.
309
        self.assertRaises(errors.NotLocalUrl,
310
                          bzrdir.BzrDir.create_standalone_workingtree,
311
                          self.get_readonly_url(), format=format)
312
        tree = bzrdir.BzrDir.create_standalone_workingtree('.', 
313
                                                           format=format)
314
        self.assertEqual('A tree', tree)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
315
1534.6.10 by Robert Collins
Finish use of repositories support.
316
    def test_create_standalone_working_tree_under_shared_repo(self):
317
        # create standalone working tree always makes a repo.
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
318
        format = bzrdir.format_registry.make_bzrdir('knit')
319
        self.make_repository('.', shared=True, format=format)
320
        # note this is deliberately readonly, as this failure should 
321
        # occur before any writes.
322
        self.assertRaises(errors.NotLocalUrl,
323
                          bzrdir.BzrDir.create_standalone_workingtree,
324
                          self.get_readonly_url('child'), format=format)
325
        tree = bzrdir.BzrDir.create_standalone_workingtree('child', 
326
            format=format)
327
        tree.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
328
329
    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.
330
        # 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
331
        format = bzrdir.format_registry.make_bzrdir('knit')
332
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
333
        branch.bzrdir.open_workingtree()
334
        branch.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
335
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
336
    def test_create_branch_convenience_possible_transports(self):
337
        """Check that the optional 'possible_transports' is recognized"""
338
        format = bzrdir.format_registry.make_bzrdir('knit')
339
        t = self.get_transport()
340
        branch = bzrdir.BzrDir.create_branch_convenience(
341
            '.', format=format, possible_transports=[t])
342
        branch.bzrdir.open_workingtree()
343
        branch.bzrdir.open_repository()
344
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
345
    def test_create_branch_convenience_root(self):
346
        """Creating a branch at the root of a fs should work."""
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
347
        self.vfs_transport_factory = MemoryServer
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
348
        # 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
349
        format = bzrdir.format_registry.make_bzrdir('knit')
350
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(), 
351
                                                         format=format)
352
        self.assertRaises(errors.NoWorkingTree,
353
                          branch.bzrdir.open_workingtree)
354
        branch.bzrdir.open_repository()
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
355
1534.6.10 by Robert Collins
Finish use of repositories support.
356
    def test_create_branch_convenience_under_shared_repo(self):
357
        # inside a repo the default convenience output is a branch+ follow the
358
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
359
        format = bzrdir.format_registry.make_bzrdir('knit')
360
        self.make_repository('.', shared=True, format=format)
361
        branch = bzrdir.BzrDir.create_branch_convenience('child',
362
            format=format)
363
        branch.bzrdir.open_workingtree()
364
        self.assertRaises(errors.NoRepositoryPresent,
365
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
366
            
367
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
368
        # inside a repo the default convenience output is a branch+ follow the
369
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
370
        format = bzrdir.format_registry.make_bzrdir('knit')
371
        self.make_repository('.', shared=True, format=format)
372
        branch = bzrdir.BzrDir.create_branch_convenience('child',
373
            force_new_tree=False, format=format)
374
        self.assertRaises(errors.NoWorkingTree,
375
                          branch.bzrdir.open_workingtree)
376
        self.assertRaises(errors.NoRepositoryPresent,
377
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
378
            
379
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
380
        # inside a repo the default convenience output is a branch+ follow the
381
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
382
        format = bzrdir.format_registry.make_bzrdir('knit')
383
        repo = self.make_repository('.', shared=True, format=format)
384
        repo.set_make_working_trees(False)
385
        branch = bzrdir.BzrDir.create_branch_convenience('child', 
386
                                                         format=format)
387
        self.assertRaises(errors.NoWorkingTree,
388
                          branch.bzrdir.open_workingtree)
389
        self.assertRaises(errors.NoRepositoryPresent,
390
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
391
392
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
393
        # inside a repo the default convenience output is a branch+ follow the
394
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
395
        format = bzrdir.format_registry.make_bzrdir('knit')
396
        repo = self.make_repository('.', shared=True, format=format)
397
        repo.set_make_working_trees(False)
398
        branch = bzrdir.BzrDir.create_branch_convenience('child',
399
            force_new_tree=True, format=format)
400
        branch.bzrdir.open_workingtree()
401
        self.assertRaises(errors.NoRepositoryPresent,
402
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
403
404
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
405
        # inside a repo the default convenience output is overridable to give
406
        # repo+branch+tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
407
        format = bzrdir.format_registry.make_bzrdir('knit')
408
        self.make_repository('.', shared=True, format=format)
409
        branch = bzrdir.BzrDir.create_branch_convenience('child',
410
            force_new_repo=True, format=format)
411
        branch.bzrdir.open_repository()
412
        branch.bzrdir.open_workingtree()
1534.6.10 by Robert Collins
Finish use of repositories support.
413
3242.2.14 by Aaron Bentley
Update from review comments
414
415
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
416
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
417
    def test_acquire_repository_standalone(self):
3242.2.14 by Aaron Bentley
Update from review comments
418
        """The default acquisition policy should create a standalone branch."""
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
419
        my_bzrdir = self.make_bzrdir('.')
420
        repo_policy = my_bzrdir.determine_repository_policy()
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
421
        repo = repo_policy.acquire_repository()
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
422
        self.assertEqual(repo.bzrdir.root_transport.base,
423
                         my_bzrdir.root_transport.base)
3242.2.14 by Aaron Bentley
Update from review comments
424
        self.assertFalse(repo.is_shared())
425
1534.4.39 by Robert Collins
Basic BzrDir support.
426
427
class ChrootedTests(TestCaseWithTransport):
428
    """A support class that provides readonly urls outside the local namespace.
429
430
    This is done by checking if self.transport_server is a MemoryServer. if it
431
    is then we are chrooted already, if it is not then an HttpServer is used
432
    for readonly urls.
433
    """
434
435
    def setUp(self):
436
        super(ChrootedTests, self).setUp()
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
437
        if not self.vfs_transport_factory == MemoryServer:
1534.4.39 by Robert Collins
Basic BzrDir support.
438
            self.transport_readonly_server = HttpServer
439
3015.3.45 by Daniel Watkins
Extract common method.
440
    def local_branch_path(self, branch):
441
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
442
1534.4.39 by Robert Collins
Basic BzrDir support.
443
    def test_open_containing(self):
444
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
445
                          self.get_readonly_url(''))
446
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
447
                          self.get_readonly_url('g/p/q'))
448
        control = bzrdir.BzrDir.create(self.get_url())
449
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
450
        self.assertEqual('', relpath)
451
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
452
        self.assertEqual('g/p/q', relpath)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
453
3015.3.46 by Daniel Watkins
Made tests more granular.
454
    def test_open_containing_tree_branch_or_repository_empty(self):
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
455
        self.assertRaises(errors.NotBranchError,
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
456
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
457
            self.get_readonly_url(''))
458
3015.3.46 by Daniel Watkins
Made tests more granular.
459
    def test_open_containing_tree_branch_or_repository_all(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
460
        self.make_branch_and_tree('topdir')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
461
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
462
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
463
                'topdir/foo')
464
        self.assertEqual(os.path.realpath('topdir'),
465
                         os.path.realpath(tree.basedir))
466
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
467
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
468
        self.assertEqual(
469
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
470
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
471
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
472
3015.3.46 by Daniel Watkins
Made tests more granular.
473
    def test_open_containing_tree_branch_or_repository_no_tree(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
474
        self.make_branch('branch')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
475
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
476
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
477
                'branch/foo')
478
        self.assertEqual(tree, None)
479
        self.assertEqual(os.path.realpath('branch'),
3015.3.45 by Daniel Watkins
Extract common method.
480
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
481
        self.assertEqual(
482
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
483
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
484
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
485
3015.3.46 by Daniel Watkins
Made tests more granular.
486
    def test_open_containing_tree_branch_or_repository_repo(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
487
        self.make_repository('repo')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
488
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
489
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
490
                'repo')
491
        self.assertEqual(tree, None)
492
        self.assertEqual(branch, None)
493
        self.assertEqual(
494
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
495
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
496
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
497
3015.3.46 by Daniel Watkins
Made tests more granular.
498
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
499
        self.make_repository('shared', shared=True)
500
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
501
                                                force_new_tree=False)
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
502
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
503
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
504
                'shared/branch')
505
        self.assertEqual(tree, None)
506
        self.assertEqual(os.path.realpath('shared/branch'),
3015.3.45 by Daniel Watkins
Extract common method.
507
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
508
        self.assertEqual(
509
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
510
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
511
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
512
3015.3.48 by Daniel Watkins
Further granulated tests.
513
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
514
        self.make_branch_and_tree('foo')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
515
        self.build_tree(['foo/bar/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
516
        tree, branch, repo, relpath = \
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
517
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
518
                'foo/bar')
519
        self.assertEqual(os.path.realpath('foo'),
520
                         os.path.realpath(tree.basedir))
521
        self.assertEqual(os.path.realpath('foo'),
3015.3.45 by Daniel Watkins
Extract common method.
522
                         self.local_branch_path(branch))
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
523
        self.assertEqual(
524
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
525
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
526
        self.assertEqual(relpath, 'bar')
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
527
3015.3.48 by Daniel Watkins
Further granulated tests.
528
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
529
        self.make_repository('bar')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
530
        self.build_tree(['bar/baz/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
531
        tree, branch, repo, relpath = \
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
532
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
533
                'bar/baz')
534
        self.assertEqual(tree, None)
535
        self.assertEqual(branch, None)
536
        self.assertEqual(
537
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
538
            repo.bzrdir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
539
        self.assertEqual(relpath, 'baz')
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
540
1534.6.11 by Robert Collins
Review feedback.
541
    def test_open_containing_from_transport(self):
542
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
1534.6.3 by Robert Collins
find_repository sufficiently robust.
543
                          get_transport(self.get_readonly_url('')))
1534.6.11 by Robert Collins
Review feedback.
544
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
1534.6.3 by Robert Collins
find_repository sufficiently robust.
545
                          get_transport(self.get_readonly_url('g/p/q')))
546
        control = bzrdir.BzrDir.create(self.get_url())
1534.6.11 by Robert Collins
Review feedback.
547
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
1534.6.3 by Robert Collins
find_repository sufficiently robust.
548
            get_transport(self.get_readonly_url('')))
549
        self.assertEqual('', relpath)
1534.6.11 by Robert Collins
Review feedback.
550
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
1534.6.3 by Robert Collins
find_repository sufficiently robust.
551
            get_transport(self.get_readonly_url('g/p/q')))
552
        self.assertEqual('g/p/q', relpath)
553
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
554
    def test_open_containing_tree_or_branch(self):
555
        self.make_branch_and_tree('topdir')
556
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
557
            'topdir/foo')
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
558
        self.assertEqual(os.path.realpath('topdir'),
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
559
                         os.path.realpath(tree.basedir))
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
560
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
561
                         self.local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
562
        self.assertIs(tree.bzrdir, branch.bzrdir)
563
        self.assertEqual('foo', relpath)
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
564
        # opening from non-local should not return the tree
565
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
566
            self.get_readonly_url('topdir/foo'))
567
        self.assertEqual(None, tree)
568
        self.assertEqual('foo', relpath)
569
        # without a tree:
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
570
        self.make_branch('topdir/foo')
571
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
572
            'topdir/foo')
573
        self.assertIs(tree, None)
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
574
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
575
                         self.local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
576
        self.assertEqual('', relpath)
577
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
578
    def test_open_tree_or_branch(self):
579
        self.make_branch_and_tree('topdir')
580
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
581
        self.assertEqual(os.path.realpath('topdir'),
582
                         os.path.realpath(tree.basedir))
583
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
584
                         self.local_branch_path(branch))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
585
        self.assertIs(tree.bzrdir, branch.bzrdir)
586
        # opening from non-local should not return the tree
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
587
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
588
            self.get_readonly_url('topdir'))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
589
        self.assertEqual(None, tree)
590
        # without a tree:
591
        self.make_branch('topdir/foo')
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
592
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
593
        self.assertIs(tree, None)
594
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
595
                         self.local_branch_path(branch))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
596
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
597
    def test_open_from_transport(self):
598
        # transport pointing at bzrdir should give a bzrdir with root transport
599
        # set to the given transport
600
        control = bzrdir.BzrDir.create(self.get_url())
601
        transport = get_transport(self.get_url())
602
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
603
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
604
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
605
        
606
    def test_open_from_transport_no_bzrdir(self):
607
        transport = get_transport(self.get_url())
608
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
609
                          transport)
610
611
    def test_open_from_transport_bzrdir_in_parent(self):
612
        control = bzrdir.BzrDir.create(self.get_url())
613
        transport = get_transport(self.get_url())
614
        transport.mkdir('subdir')
615
        transport = transport.clone('subdir')
616
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
617
                          transport)
618
2100.3.28 by Aaron Bentley
Make sprout recursive
619
    def test_sprout_recursive(self):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
620
        tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
2100.3.28 by Aaron Bentley
Make sprout recursive
621
        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.
622
            format='dirstate-with-subtree')
2100.3.28 by Aaron Bentley
Make sprout recursive
623
        tree.add_reference(sub_tree)
624
        self.build_tree(['tree1/subtree/file'])
625
        sub_tree.add('file')
626
        tree.commit('Initial commit')
627
        tree.bzrdir.sprout('tree2')
628
        self.failUnlessExists('tree2/subtree/file')
629
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
630
    def test_cloning_metadir(self):
631
        """Ensure that cloning metadir is suitable"""
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
632
        bzrdir = self.make_bzrdir('bzrdir')
633
        bzrdir.cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
634
        branch = self.make_branch('branch', format='knit')
635
        format = branch.bzrdir.cloning_metadir()
636
        self.assertIsInstance(format.workingtree_format,
2255.2.174 by Martin Pool
remove AB1 WorkingTree and experimental-knit3
637
            workingtree.WorkingTreeFormat3)
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
638
639
    def test_sprout_recursive_treeless(self):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
640
        tree = self.make_branch_and_tree('tree1',
641
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
642
        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.
643
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
644
        tree.add_reference(sub_tree)
645
        self.build_tree(['tree1/subtree/file'])
646
        sub_tree.add('file')
647
        tree.commit('Initial commit')
648
        tree.bzrdir.destroy_workingtree()
649
        repo = self.make_repository('repo', shared=True,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
650
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
651
        repo.set_make_working_trees(False)
652
        tree.bzrdir.sprout('repo/tree2')
653
        self.failUnlessExists('repo/tree2/subtree')
654
        self.failIfExists('repo/tree2/subtree/file')
655
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
656
    def make_foo_bar_baz(self):
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
657
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
658
        bar = self.make_branch('foo/bar').bzrdir
659
        baz = self.make_branch('baz').bzrdir
660
        return foo, bar, baz
661
662
    def test_find_bzrdirs(self):
663
        foo, bar, baz = self.make_foo_bar_baz()
664
        transport = get_transport(self.get_url())
665
        self.assertEqualBzrdirs([baz, foo, bar],
666
                                bzrdir.BzrDir.find_bzrdirs(transport))
667
668
    def test_find_bzrdirs_list_current(self):
669
        def list_current(transport):
670
            return [s for s in transport.list_dir('') if s != 'baz']
671
672
        foo, bar, baz = self.make_foo_bar_baz()
673
        transport = get_transport(self.get_url())
674
        self.assertEqualBzrdirs([foo, bar],
675
                                bzrdir.BzrDir.find_bzrdirs(transport,
676
                                    list_current=list_current))
677
678
679
    def test_find_bzrdirs_evaluate(self):
680
        def evaluate(bzrdir):
681
            try:
682
                repo = bzrdir.open_repository()
683
            except NoRepositoryPresent:
684
                return True, bzrdir.root_transport.base
685
            else:
686
                return False, bzrdir.root_transport.base
687
688
        foo, bar, baz = self.make_foo_bar_baz()
689
        transport = get_transport(self.get_url())
690
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
691
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
692
                                                         evaluate=evaluate)))
693
694
    def assertEqualBzrdirs(self, first, second):
695
        first = list(first)
696
        second = list(second)
697
        self.assertEqual(len(first), len(second))
698
        for x, y in zip(first, second):
699
            self.assertEqual(x.root_transport.base, y.root_transport.base)
700
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
701
    def test_find_branches(self):
702
        root = self.make_repository('', shared=True)
703
        foo, bar, baz = self.make_foo_bar_baz()
704
        qux = self.make_bzrdir('foo/qux')
705
        transport = get_transport(self.get_url())
706
        branches = bzrdir.BzrDir.find_branches(transport)
707
        self.assertEqual(baz.root_transport.base, branches[0].base)
708
        self.assertEqual(foo.root_transport.base, branches[1].base)
709
        self.assertEqual(bar.root_transport.base, branches[2].base)
710
711
        # ensure this works without a top-level repo
712
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
713
        self.assertEqual(foo.root_transport.base, branches[0].base)
714
        self.assertEqual(bar.root_transport.base, branches[1].base)
715
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
716
717
class TestMeta1DirFormat(TestCaseWithTransport):
718
    """Tests specific to the meta1 dir format."""
719
720
    def test_right_base_dirs(self):
721
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
722
        t = dir.transport
723
        branch_base = t.clone('branch').base
724
        self.assertEqual(branch_base, dir.get_branch_transport(None).base)
725
        self.assertEqual(branch_base,
1508.1.25 by Robert Collins
Update per review comments.
726
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
727
        repository_base = t.clone('repository').base
728
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
729
        self.assertEqual(repository_base,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
730
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
731
        checkout_base = t.clone('checkout').base
732
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
733
        self.assertEqual(checkout_base,
734
                         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.
735
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
736
    def test_meta1dir_uses_lockdir(self):
737
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
738
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
739
        t = dir.transport
740
        self.assertIsDirectory('branch-lock', t)
741
2100.3.35 by Aaron Bentley
equality operations on bzrdir
742
    def test_comparison(self):
743
        """Equality and inequality behave properly.
744
745
        Metadirs should compare equal iff they have the same repo, branch and
746
        tree formats.
747
        """
748
        mydir = bzrdir.format_registry.make_bzrdir('knit')
749
        self.assertEqual(mydir, mydir)
750
        self.assertFalse(mydir != mydir)
751
        otherdir = bzrdir.format_registry.make_bzrdir('knit')
752
        self.assertEqual(otherdir, mydir)
753
        self.assertFalse(otherdir != mydir)
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
754
        otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
2100.3.35 by Aaron Bentley
equality operations on bzrdir
755
        self.assertNotEqual(otherdir2, mydir)
756
        self.assertFalse(otherdir2 == mydir)
757
2255.12.1 by Robert Collins
Implement upgrade for working trees.
758
    def test_needs_conversion_different_working_tree(self):
759
        # meta1dirs need an conversion if any element is not the default.
760
        old_format = bzrdir.BzrDirFormat.get_default_format()
761
        # test with 
762
        new_default = bzrdir.format_registry.make_bzrdir('dirstate')
763
        bzrdir.BzrDirFormat._set_default_format(new_default)
764
        try:
765
            tree = self.make_branch_and_tree('tree', format='knit')
766
            self.assertTrue(tree.bzrdir.needs_format_conversion())
767
        finally:
768
            bzrdir.BzrDirFormat._set_default_format(old_format)
769
770
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
771
class TestFormat5(TestCaseWithTransport):
772
    """Tests specific to the version 5 bzrdir format."""
773
774
    def test_same_lockfiles_between_tree_repo_branch(self):
775
        # this checks that only a single lockfiles instance is created 
776
        # for format 5 objects
777
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
778
        def check_dir_components_use_same_lock(dir):
779
            ctrl_1 = dir.open_repository().control_files
780
            ctrl_2 = dir.open_branch().control_files
781
            ctrl_3 = dir.open_workingtree()._control_files
782
            self.assertTrue(ctrl_1 is ctrl_2)
783
            self.assertTrue(ctrl_2 is ctrl_3)
784
        check_dir_components_use_same_lock(dir)
785
        # and if we open it normally.
786
        dir = bzrdir.BzrDir.open(self.get_url())
787
        check_dir_components_use_same_lock(dir)
788
    
1534.5.16 by Robert Collins
Review feedback.
789
    def test_can_convert(self):
790
        # format 5 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
791
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
792
        self.assertTrue(dir.can_convert_format())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
793
    
1534.5.16 by Robert Collins
Review feedback.
794
    def test_needs_conversion(self):
795
        # 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.
796
        # and they start of not the default.
797
        old_format = bzrdir.BzrDirFormat.get_default_format()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
798
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
799
        try:
800
            dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
801
            self.assertFalse(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
802
        finally:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
803
            bzrdir.BzrDirFormat._set_default_format(old_format)
1534.5.16 by Robert Collins
Review feedback.
804
        self.assertTrue(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
805
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
806
807
class TestFormat6(TestCaseWithTransport):
808
    """Tests specific to the version 6 bzrdir format."""
809
810
    def test_same_lockfiles_between_tree_repo_branch(self):
811
        # this checks that only a single lockfiles instance is created 
812
        # for format 6 objects
813
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
814
        def check_dir_components_use_same_lock(dir):
815
            ctrl_1 = dir.open_repository().control_files
816
            ctrl_2 = dir.open_branch().control_files
817
            ctrl_3 = dir.open_workingtree()._control_files
818
            self.assertTrue(ctrl_1 is ctrl_2)
819
            self.assertTrue(ctrl_2 is ctrl_3)
820
        check_dir_components_use_same_lock(dir)
821
        # and if we open it normally.
822
        dir = bzrdir.BzrDir.open(self.get_url())
823
        check_dir_components_use_same_lock(dir)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
824
    
1534.5.16 by Robert Collins
Review feedback.
825
    def test_can_convert(self):
826
        # format 6 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
827
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
828
        self.assertTrue(dir.can_convert_format())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
829
    
1534.5.16 by Robert Collins
Review feedback.
830
    def test_needs_conversion(self):
831
        # 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.
832
        old_format = bzrdir.BzrDirFormat.get_default_format()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
833
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
834
        try:
835
            dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
836
            self.assertTrue(dir.needs_format_conversion())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
837
        finally:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
838
            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.
839
840
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
841
class NotBzrDir(bzrlib.bzrdir.BzrDir):
842
    """A non .bzr based control directory."""
843
844
    def __init__(self, transport, format):
845
        self._format = format
846
        self.root_transport = transport
847
        self.transport = transport.clone('.not')
848
849
850
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
851
    """A test class representing any non-.bzr based disk format."""
852
853
    def initialize_on_transport(self, transport):
854
        """Initialize a new .not dir in the base directory of a Transport."""
855
        transport.mkdir('.not')
856
        return self.open(transport)
857
858
    def open(self, transport):
859
        """Open this directory."""
860
        return NotBzrDir(transport, self)
861
862
    @classmethod
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
863
    def _known_formats(self):
864
        return set([NotBzrDirFormat()])
865
866
    @classmethod
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
867
    def probe_transport(self, transport):
868
        """Our format is present if the transport ends in '.not/'."""
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
869
        if transport.has('.not'):
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
870
            return NotBzrDirFormat()
871
872
873
class TestNotBzrDir(TestCaseWithTransport):
874
    """Tests for using the bzrdir api with a non .bzr based disk format.
875
    
876
    If/when one of these is in the core, we can let the implementation tests
877
    verify this works.
878
    """
879
880
    def test_create_and_find_format(self):
881
        # create a .notbzr dir 
882
        format = NotBzrDirFormat()
883
        dir = format.initialize(self.get_url())
884
        self.assertIsInstance(dir, NotBzrDir)
885
        # now probe for it.
886
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
887
        try:
888
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
889
                get_transport(self.get_url()))
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
890
            self.assertIsInstance(found, NotBzrDirFormat)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
891
        finally:
892
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
893
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
894
    def test_included_in_known_formats(self):
895
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
896
        try:
897
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
898
            for format in formats:
899
                if isinstance(format, NotBzrDirFormat):
900
                    return
901
            self.fail("No NotBzrDirFormat in %s" % formats)
902
        finally:
903
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
904
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
905
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.
906
class NonLocalTests(TestCaseWithTransport):
907
    """Tests for bzrdir static behaviour on non local paths."""
908
909
    def setUp(self):
910
        super(NonLocalTests, self).setUp()
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
911
        self.vfs_transport_factory = MemoryServer
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.
912
    
913
    def test_create_branch_convenience(self):
914
        # 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
915
        format = bzrdir.format_registry.make_bzrdir('knit')
916
        branch = bzrdir.BzrDir.create_branch_convenience(
917
            self.get_url('foo'), format=format)
918
        self.assertRaises(errors.NoWorkingTree,
919
                          branch.bzrdir.open_workingtree)
920
        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.
921
922
    def test_create_branch_convenience_force_tree_not_local_fails(self):
923
        # 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
924
        format = bzrdir.format_registry.make_bzrdir('knit')
925
        self.assertRaises(errors.NotLocalUrl,
926
            bzrdir.BzrDir.create_branch_convenience,
927
            self.get_url('foo'),
928
            force_new_tree=True,
929
            format=format)
930
        t = get_transport(self.get_url('.'))
931
        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.
932
1563.2.38 by Robert Collins
make push preserve tree formats.
933
    def test_clone(self):
934
        # clone into a nonlocal path works
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
935
        format = bzrdir.format_registry.make_bzrdir('knit')
936
        branch = bzrdir.BzrDir.create_branch_convenience('local',
937
                                                         format=format)
1563.2.38 by Robert Collins
make push preserve tree formats.
938
        branch.bzrdir.open_workingtree()
939
        result = branch.bzrdir.clone(self.get_url('remote'))
940
        self.assertRaises(errors.NoWorkingTree,
941
                          result.open_workingtree)
942
        result.open_branch()
943
        result.open_repository()
944
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
945
    def test_checkout_metadir(self):
946
        # checkout_metadir has reasonable working tree format even when no
947
        # working tree is present
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
948
        self.make_branch('branch-knit2', format='dirstate-with-subtree')
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
949
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
950
        checkout_format = my_bzrdir.checkout_metadir()
951
        self.assertIsInstance(checkout_format.workingtree_format,
952
                              workingtree.WorkingTreeFormat3)
2100.3.22 by Aaron Bentley
merge from bzr.dev
953
2215.3.5 by Aaron Bentley
Add support for remote ls
954
2164.2.16 by Vincent Ladeuil
Add tests.
955
class TestHTTPRedirectionLoop(object):
956
    """Test redirection loop between two http servers.
957
958
    This MUST be used by daughter classes that also inherit from
959
    TestCaseWithTwoWebservers.
960
961
    We can't inherit directly from TestCaseWithTwoWebservers or the
962
    test framework will try to create an instance which cannot
963
    run, its implementation being incomplete. 
964
    """
965
966
    # Should be defined by daughter classes to ensure redirection
2164.2.17 by Vincent Ladeuil
Add comments and fix typos
967
    # still use the same transport implementation (not currently
968
    # enforced as it's a bit tricky to get right (see the FIXME
969
    # in BzrDir.open_from_transport for the unique use case so
970
    # far)
2164.2.16 by Vincent Ladeuil
Add tests.
971
    _qualifier = None
972
973
    def create_transport_readonly_server(self):
974
        return HTTPServerRedirecting()
975
976
    def create_transport_secondary_server(self):
977
        return HTTPServerRedirecting()
978
979
    def setUp(self):
980
        # Both servers redirect to each server creating a loop
981
        super(TestHTTPRedirectionLoop, self).setUp()
982
        # The redirections will point to the new server
983
        self.new_server = self.get_readonly_server()
984
        # The requests to the old server will be redirected
985
        self.old_server = self.get_secondary_server()
986
        # Configure the redirections
987
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
988
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
989
990
    def _qualified_url(self, host, port):
991
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
992
993
    def test_loop(self):
994
        # Starting from either server should loop
995
        old_url = self._qualified_url(self.old_server.host, 
996
                                      self.old_server.port)
997
        oldt = self._transport(old_url)
998
        self.assertRaises(errors.NotBranchError,
999
                          bzrdir.BzrDir.open_from_transport, oldt)
1000
        new_url = self._qualified_url(self.new_server.host, 
1001
                                      self.new_server.port)
1002
        newt = self._transport(new_url)
1003
        self.assertRaises(errors.NotBranchError,
1004
                          bzrdir.BzrDir.open_from_transport, newt)
1005
1006
1007
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
1008
                                  TestCaseWithTwoWebservers):
1009
    """Tests redirections for urllib implementation"""
1010
1011
    _qualifier = 'urllib'
1012
    _transport = HttpTransport_urllib
1013
1014
1015
1016
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
1017
                                  TestHTTPRedirectionLoop,
1018
                                  TestCaseWithTwoWebservers):
1019
    """Tests redirections for pycurl implementation"""
1020
1021
    _qualifier = 'pycurl'
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1022
1023
1024
class TestDotBzrHidden(TestCaseWithTransport):
1025
3023.1.3 by Alexander Belchenko
John's review
1026
    ls = ['ls']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1027
    if sys.platform == 'win32':
3023.1.3 by Alexander Belchenko
John's review
1028
        ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1029
1030
    def get_ls(self):
3023.1.3 by Alexander Belchenko
John's review
1031
        f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
1032
            stderr=subprocess.PIPE)
1033
        out, err = f.communicate()
1034
        self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1035
                         % (self.ls, err))
1036
        return out.splitlines()
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1037
1038
    def test_dot_bzr_hidden(self):
3023.1.2 by Alexander Belchenko
Martin's review.
1039
        if sys.platform == 'win32' and not win32utils.has_win32file:
1040
            raise TestSkipped('unable to make file hidden without pywin32 library')
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1041
        b = bzrdir.BzrDir.create('.')
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
1042
        self.build_tree(['a'])
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1043
        self.assertEquals(['a'], self.get_ls())
1044
1045
    def test_dot_bzr_hidden_with_url(self):
3023.1.2 by Alexander Belchenko
Martin's review.
1046
        if sys.platform == 'win32' and not win32utils.has_win32file:
1047
            raise TestSkipped('unable to make file hidden without pywin32 library')
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1048
        b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
1049
        self.build_tree(['a'])
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1050
        self.assertEquals(['a'], self.get_ls())