/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.39 by Robert Collins
Basic BzrDir support.
16
17
"""Tests for the BzrDir facility and any format specific tests.
18
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
19
For interface contract tests, see tests/per_bzr_dir.
1534.4.39 by Robert Collins
Basic BzrDir support.
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
3023.1.3 by Alexander Belchenko
John's review
23
import subprocess
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
24
import sys
1534.4.39 by Robert Collins
Basic BzrDir support.
25
2204.4.1 by Aaron Bentley
Add 'formats' help topic
26
from bzrlib import (
5215.4.1 by Marius Kruger
BzrDir.find_branches should not fall over when encountering branches with missing repos
27
    branch,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
28
    bzrdir,
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
29
    controldir,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
30
    errors,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
31
    help_topics,
5536.1.13 by Andrew Bennetts
Fix a test failure (_TestBranch needs to implement lock_read/unlock).
32
    lock,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
33
    repository,
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
34
    osutils,
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
35
    remote,
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
36
    symbol_versioning,
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
37
    transport as _mod_transport,
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
38
    urlutils,
3023.1.2 by Alexander Belchenko
Martin's review.
39
    win32utils,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
40
    workingtree,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
41
    )
1508.1.25 by Robert Collins
Update per review comments.
42
import bzrlib.branch
1534.4.39 by Robert Collins
Basic BzrDir support.
43
from bzrlib.errors import (NotBranchError,
5051.3.3 by Jelmer Vernooij
Add tests for colo branches.
44
                           NoColocatedBranchSupport,
1534.4.39 by Robert Collins
Basic BzrDir support.
45
                           UnknownFormatError,
46
                           UnsupportedFormatError,
47
                           )
2164.2.16 by Vincent Ladeuil
Add tests.
48
from bzrlib.tests import (
49
    TestCase,
3583.1.2 by Andrew Bennetts
Add test for fix.
50
    TestCaseWithMemoryTransport,
2164.2.16 by Vincent Ladeuil
Add tests.
51
    TestCaseWithTransport,
3023.1.2 by Alexander Belchenko
Martin's review.
52
    TestSkipped,
2164.2.16 by Vincent Ladeuil
Add tests.
53
    )
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
54
from bzrlib.tests import(
55
    http_server,
56
    http_utils,
2164.2.16 by Vincent Ladeuil
Add tests.
57
    )
58
from bzrlib.tests.test_http import TestWithTransport_pycurl
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
59
from bzrlib.transport import (
60
    memory,
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
61
    pathfilter,
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
62
    )
2164.2.16 by Vincent Ladeuil
Add tests.
63
from bzrlib.transport.http._urllib import HttpTransport_urllib
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
64
from bzrlib.transport.nosmart import NoSmartTransportDecorator
65
from bzrlib.transport.readonly import ReadonlyTransportDecorator
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
66
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
1534.4.39 by Robert Collins
Basic BzrDir support.
67
68
69
class TestDefaultFormat(TestCase):
70
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
71
    def test_get_set_default_format(self):
1534.4.39 by Robert Collins
Basic BzrDir support.
72
        old_format = bzrdir.BzrDirFormat.get_default_format()
73
        # default is BzrDirFormat6
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
74
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
5363.2.7 by Jelmer Vernooij
Fix tests.
75
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
1534.4.39 by Robert Collins
Basic BzrDir support.
76
        # creating a bzr dir should now create an instrumented dir.
77
        try:
1685.1.42 by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly.
78
            result = bzrdir.BzrDir.create('memory:///')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
79
            self.failUnless(isinstance(result, SampleBzrDir))
1534.4.39 by Robert Collins
Basic BzrDir support.
80
        finally:
5363.2.7 by Jelmer Vernooij
Fix tests.
81
            controldir.ControlDirFormat._set_default_format(old_format)
1534.4.39 by Robert Collins
Basic BzrDir support.
82
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
83
84
2204.4.1 by Aaron Bentley
Add 'formats' help topic
85
class TestFormatRegistry(TestCase):
86
87
    def make_format_registry(self):
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
88
        my_format_registry = controldir.ControlDirFormatRegistry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
89
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
90
            '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
91
            ' repositories', deprecated=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
92
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
93
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
94
        bzrdir.register_metadir(my_format_registry, 'knit',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
95
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
96
            'Format using knits',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
97
            )
2204.4.1 by Aaron Bentley
Add 'formats' help topic
98
        my_format_registry.set_default('knit')
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
99
        bzrdir.register_metadir(my_format_registry,
2230.3.53 by Aaron Bentley
Merge bzr.dev
100
            'branch6',
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
101
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2230.3.53 by Aaron Bentley
Merge bzr.dev
102
            'Experimental successor to knit.  Use at your own risk.',
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
103
            branch_format='bzrlib.branch.BzrBranchFormat6',
104
            experimental=True)
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
105
        bzrdir.register_metadir(my_format_registry,
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
106
            'hidden format',
107
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
108
            'Experimental successor to knit.  Use at your own risk.',
109
            branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
110
        my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
111
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
112
            ' repositories', hidden=True)
113
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
114
            'BzrDirFormat6', 'Format registered lazily', deprecated=True,
115
            hidden=True)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
116
        return my_format_registry
117
118
    def test_format_registry(self):
119
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
120
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
121
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
122
        my_bzrdir = my_format_registry.make_bzrdir('weave')
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
123
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
124
        my_bzrdir = my_format_registry.make_bzrdir('default')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
125
        self.assertIsInstance(my_bzrdir.repository_format,
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
126
            knitrepo.RepositoryFormatKnit1)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
127
        my_bzrdir = my_format_registry.make_bzrdir('knit')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
128
        self.assertIsInstance(my_bzrdir.repository_format,
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
129
            knitrepo.RepositoryFormatKnit1)
2230.3.1 by Aaron Bentley
Get branch6 creation working
130
        my_bzrdir = my_format_registry.make_bzrdir('branch6')
2230.3.55 by Aaron Bentley
Updates from review
131
        self.assertIsInstance(my_bzrdir.get_branch_format(),
2230.3.1 by Aaron Bentley
Get branch6 creation working
132
                              bzrlib.branch.BzrBranchFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
133
134
    def test_get_help(self):
135
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
136
        self.assertEqual('Format registered lazily',
137
                         my_format_registry.get_help('lazy'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
138
        self.assertEqual('Format using knits',
2204.4.1 by Aaron Bentley
Add 'formats' help topic
139
                         my_format_registry.get_help('knit'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
140
        self.assertEqual('Format using knits',
2204.4.1 by Aaron Bentley
Add 'formats' help topic
141
                         my_format_registry.get_help('default'))
142
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
143
                         ' checkouts or shared repositories',
2204.4.1 by Aaron Bentley
Add 'formats' help topic
144
                         my_format_registry.get_help('weave'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
145
2204.4.1 by Aaron Bentley
Add 'formats' help topic
146
    def test_help_topic(self):
147
        topics = help_topics.HelpTopicRegistry()
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
148
        registry = self.make_format_registry()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
149
        topics.register('current-formats', registry.help_topic,
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
150
                        'Current formats')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
151
        topics.register('other-formats', registry.help_topic,
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
152
                        'Other formats')
153
        new = topics.get_detail('current-formats')
154
        rest = topics.get_detail('other-formats')
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
155
        experimental, deprecated = rest.split('Deprecated formats')
4927.2.10 by Ian Clatworthy
fix test failures
156
        self.assertContainsRe(new, 'formats-help')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
157
        self.assertContainsRe(new,
2666.1.8 by Ian Clatworthy
Fix storage formats help test
158
                ':knit:\n    \(native\) \(default\) Format using knits\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
159
        self.assertContainsRe(experimental,
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
160
                ':branch6:\n    \(native\) Experimental successor to knit')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
161
        self.assertContainsRe(deprecated,
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
162
                ':lazy:\n    \(native\) Format registered lazily\n')
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
163
        self.assertNotContainsRe(new, 'hidden')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
164
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
165
    def test_set_default_repository(self):
166
        default_factory = bzrdir.format_registry.get('default')
167
        old_default = [k for k, v in bzrdir.format_registry.iteritems()
168
                       if v == default_factory and k != 'default'][0]
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
169
        bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
170
        try:
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
171
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
172
                          bzrdir.format_registry.get('default'))
173
            self.assertIs(
174
                repository.RepositoryFormat.get_default_format().__class__,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
175
                knitrepo.RepositoryFormatKnit3)
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
176
        finally:
177
            bzrdir.format_registry.set_default_repository(old_default)
178
3152.2.2 by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to
179
    def test_aliases(self):
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
180
        a_registry = controldir.ControlDirFormatRegistry()
3152.2.2 by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to
181
        a_registry.register('weave', bzrdir.BzrDirFormat6,
182
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
183
            ' repositories', deprecated=True)
184
        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
185
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
186
            ' repositories', deprecated=True, alias=True)
187
        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
188
2220.2.25 by Martin Pool
doc
189
1508.1.25 by Robert Collins
Update per review comments.
190
class SampleBranch(bzrlib.branch.Branch):
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
191
    """A dummy branch for guess what, dummy use."""
192
193
    def __init__(self, dir):
194
        self.bzrdir = dir
195
196
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
197
class SampleRepository(bzrlib.repository.Repository):
198
    """A dummy repo."""
199
200
    def __init__(self, dir):
201
        self.bzrdir = dir
202
203
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
204
class SampleBzrDir(bzrdir.BzrDir):
205
    """A sample BzrDir implementation to allow testing static methods."""
206
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
207
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
208
        """See BzrDir.create_repository."""
209
        return "A repository"
210
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.
211
    def open_repository(self):
212
        """See BzrDir.open_repository."""
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
213
        return SampleRepository(self)
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.
214
5051.3.3 by Jelmer Vernooij
Add tests for colo branches.
215
    def create_branch(self, name=None):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
216
        """See BzrDir.create_branch."""
5051.3.3 by Jelmer Vernooij
Add tests for colo branches.
217
        if name is not None:
218
            raise NoColocatedBranchSupport(self)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
219
        return SampleBranch(self)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
220
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
221
    def create_workingtree(self):
222
        """See BzrDir.create_workingtree."""
223
        return "A tree"
224
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
225
1534.4.39 by Robert Collins
Basic BzrDir support.
226
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
227
    """A sample format
228
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
229
    this format is initializable, unsupported to aid in testing the
1534.4.39 by Robert Collins
Basic BzrDir support.
230
    open and open_downlevel routines.
231
    """
232
233
    def get_format_string(self):
234
        """See BzrDirFormat.get_format_string()."""
235
        return "Sample .bzr dir format."
236
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
237
    def initialize_on_transport(self, t):
1534.4.39 by Robert Collins
Basic BzrDir support.
238
        """Create a bzr dir."""
239
        t.mkdir('.bzr')
1955.3.9 by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes
240
        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.
241
        return SampleBzrDir(t, self)
1534.4.39 by Robert Collins
Basic BzrDir support.
242
243
    def is_supported(self):
244
        return False
245
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
246
    def open(self, transport, _found=None):
1534.4.39 by Robert Collins
Basic BzrDir support.
247
        return "opened branch."
248
249
250
class TestBzrDirFormat(TestCaseWithTransport):
251
    """Tests for the BzrDirFormat facility."""
252
253
    def test_find_format(self):
254
        # is the right format object found for a branch?
255
        # create a branch with a few known format objects.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
256
        # this is not quite the same as
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
257
        t = self.get_transport()
1534.4.39 by Robert Collins
Basic BzrDir support.
258
        self.build_tree(["foo/", "bar/"], transport=t)
259
        def check_format(format, url):
260
            format.initialize(url)
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
261
            t = _mod_transport.get_transport(url)
1534.4.39 by Robert Collins
Basic BzrDir support.
262
            found_format = bzrdir.BzrDirFormat.find_format(t)
263
            self.failUnless(isinstance(found_format, format.__class__))
264
        check_format(bzrdir.BzrDirFormat5(), "foo")
265
        check_format(bzrdir.BzrDirFormat6(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
266
1534.4.39 by Robert Collins
Basic BzrDir support.
267
    def test_find_format_nothing_there(self):
268
        self.assertRaises(NotBranchError,
269
                          bzrdir.BzrDirFormat.find_format,
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
270
                          _mod_transport.get_transport('.'))
1534.4.39 by Robert Collins
Basic BzrDir support.
271
272
    def test_find_format_unknown_format(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
273
        t = self.get_transport()
1534.4.39 by Robert Collins
Basic BzrDir support.
274
        t.mkdir('.bzr')
1955.3.13 by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings.
275
        t.put_bytes('.bzr/branch-format', '')
1534.4.39 by Robert Collins
Basic BzrDir support.
276
        self.assertRaises(UnknownFormatError,
277
                          bzrdir.BzrDirFormat.find_format,
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
278
                          _mod_transport.get_transport('.'))
1534.4.39 by Robert Collins
Basic BzrDir support.
279
280
    def test_register_unregister_format(self):
281
        format = SampleBzrDirFormat()
282
        url = self.get_url()
283
        # make a bzrdir
284
        format.initialize(url)
285
        # register a format for it.
286
        bzrdir.BzrDirFormat.register_format(format)
287
        # which bzrdir.Open will refuse (not supported)
288
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
289
        # which bzrdir.open_containing will refuse (not supported)
290
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
1534.4.39 by Robert Collins
Basic BzrDir support.
291
        # but open_downlevel will work
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
292
        t = _mod_transport.get_transport(url)
1534.4.39 by Robert Collins
Basic BzrDir support.
293
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
294
        # unregister the format
295
        bzrdir.BzrDirFormat.unregister_format(format)
296
        # now open_downlevel should fail too.
297
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
298
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.
299
    def test_create_branch_and_repo_uses_default(self):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
300
        format = SampleBzrDirFormat()
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
301
        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
302
                                                      format=format)
303
        self.assertTrue(isinstance(branch, SampleBranch))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
304
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
305
    def test_create_branch_and_repo_under_shared(self):
306
        # creating a branch and repo in a shared repo uses the
307
        # shared repository
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
308
        format = bzrdir.format_registry.make_bzrdir('knit')
309
        self.make_repository('.', shared=True, format=format)
310
        branch = bzrdir.BzrDir.create_branch_and_repo(
311
            self.get_url('child'), format=format)
312
        self.assertRaises(errors.NoRepositoryPresent,
313
                          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.
314
315
    def test_create_branch_and_repo_under_shared_force_new(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
316
        # creating a branch and repo in a shared repo can be forced to
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.
317
        # make a new 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
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
321
                                                      force_new_repo=True,
322
                                                      format=format)
323
        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.
324
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
325
    def test_create_standalone_working_tree(self):
326
        format = SampleBzrDirFormat()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
327
        # note this is deliberately readonly, as this failure should
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
328
        # occur before any writes.
329
        self.assertRaises(errors.NotLocalUrl,
330
                          bzrdir.BzrDir.create_standalone_workingtree,
331
                          self.get_readonly_url(), format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
332
        tree = bzrdir.BzrDir.create_standalone_workingtree('.',
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
333
                                                           format=format)
334
        self.assertEqual('A tree', tree)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
335
1534.6.10 by Robert Collins
Finish use of repositories support.
336
    def test_create_standalone_working_tree_under_shared_repo(self):
337
        # create standalone working tree always makes a repo.
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
338
        format = bzrdir.format_registry.make_bzrdir('knit')
339
        self.make_repository('.', shared=True, format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
340
        # note this is deliberately readonly, as this failure should
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
341
        # occur before any writes.
342
        self.assertRaises(errors.NotLocalUrl,
343
                          bzrdir.BzrDir.create_standalone_workingtree,
344
                          self.get_readonly_url('child'), format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
345
        tree = bzrdir.BzrDir.create_standalone_workingtree('child',
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
346
            format=format)
347
        tree.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
348
349
    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.
350
        # 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
351
        format = bzrdir.format_registry.make_bzrdir('knit')
352
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
353
        branch.bzrdir.open_workingtree()
354
        branch.bzrdir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
355
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
356
    def test_create_branch_convenience_possible_transports(self):
357
        """Check that the optional 'possible_transports' is recognized"""
358
        format = bzrdir.format_registry.make_bzrdir('knit')
359
        t = self.get_transport()
360
        branch = bzrdir.BzrDir.create_branch_convenience(
361
            '.', format=format, possible_transports=[t])
362
        branch.bzrdir.open_workingtree()
363
        branch.bzrdir.open_repository()
364
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
365
    def test_create_branch_convenience_root(self):
366
        """Creating a branch at the root of a fs should work."""
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
367
        self.vfs_transport_factory = memory.MemoryServer
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
368
        # 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
369
        format = bzrdir.format_registry.make_bzrdir('knit')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
370
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
371
                                                         format=format)
372
        self.assertRaises(errors.NoWorkingTree,
373
                          branch.bzrdir.open_workingtree)
374
        branch.bzrdir.open_repository()
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
375
1534.6.10 by Robert Collins
Finish use of repositories support.
376
    def test_create_branch_convenience_under_shared_repo(self):
377
        # inside a repo the default convenience output is a branch+ follow the
378
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
379
        format = bzrdir.format_registry.make_bzrdir('knit')
380
        self.make_repository('.', shared=True, format=format)
381
        branch = bzrdir.BzrDir.create_branch_convenience('child',
382
            format=format)
383
        branch.bzrdir.open_workingtree()
384
        self.assertRaises(errors.NoRepositoryPresent,
385
                          branch.bzrdir.open_repository)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
386
1534.6.10 by Robert Collins
Finish use of repositories support.
387
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
388
        # inside a repo the default convenience output is a branch+ follow the
389
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
390
        format = bzrdir.format_registry.make_bzrdir('knit')
391
        self.make_repository('.', shared=True, format=format)
392
        branch = bzrdir.BzrDir.create_branch_convenience('child',
393
            force_new_tree=False, format=format)
394
        self.assertRaises(errors.NoWorkingTree,
395
                          branch.bzrdir.open_workingtree)
396
        self.assertRaises(errors.NoRepositoryPresent,
397
                          branch.bzrdir.open_repository)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
398
1534.6.10 by Robert Collins
Finish use of repositories support.
399
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
400
        # inside a repo the default convenience output is a branch+ follow the
401
        # repo tree policy
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
402
        format = bzrdir.format_registry.make_bzrdir('knit')
403
        repo = self.make_repository('.', shared=True, format=format)
404
        repo.set_make_working_trees(False)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
405
        branch = bzrdir.BzrDir.create_branch_convenience('child',
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
406
                                                         format=format)
407
        self.assertRaises(errors.NoWorkingTree,
408
                          branch.bzrdir.open_workingtree)
409
        self.assertRaises(errors.NoRepositoryPresent,
410
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
411
412
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
413
        # inside a repo the default convenience output is a branch+ follow the
414
        # repo tree policy but we can override that
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
415
        format = bzrdir.format_registry.make_bzrdir('knit')
416
        repo = self.make_repository('.', shared=True, format=format)
417
        repo.set_make_working_trees(False)
418
        branch = bzrdir.BzrDir.create_branch_convenience('child',
419
            force_new_tree=True, format=format)
420
        branch.bzrdir.open_workingtree()
421
        self.assertRaises(errors.NoRepositoryPresent,
422
                          branch.bzrdir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
423
424
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
425
        # inside a repo the default convenience output is overridable to give
426
        # repo+branch+tree
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
427
        format = bzrdir.format_registry.make_bzrdir('knit')
428
        self.make_repository('.', shared=True, format=format)
429
        branch = bzrdir.BzrDir.create_branch_convenience('child',
430
            force_new_repo=True, format=format)
431
        branch.bzrdir.open_repository()
432
        branch.bzrdir.open_workingtree()
1534.6.10 by Robert Collins
Finish use of repositories support.
433
3242.2.14 by Aaron Bentley
Update from review comments
434
435
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
436
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
437
    def test_acquire_repository_standalone(self):
3242.2.14 by Aaron Bentley
Update from review comments
438
        """The default acquisition policy should create a standalone branch."""
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
439
        my_bzrdir = self.make_bzrdir('.')
440
        repo_policy = my_bzrdir.determine_repository_policy()
4070.9.2 by Andrew Bennetts
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.
441
        repo, is_new = repo_policy.acquire_repository()
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
442
        self.assertEqual(repo.bzrdir.root_transport.base,
443
                         my_bzrdir.root_transport.base)
3242.2.14 by Aaron Bentley
Update from review comments
444
        self.assertFalse(repo.is_shared())
445
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
446
    def test_determine_stacking_policy(self):
447
        parent_bzrdir = self.make_bzrdir('.')
448
        child_bzrdir = self.make_bzrdir('child')
3242.3.11 by Aaron Bentley
Clean up BzrDirConfig usage
449
        parent_bzrdir.get_config().set_default_stack_on('http://example.org')
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
450
        repo_policy = child_bzrdir.determine_repository_policy()
451
        self.assertEqual('http://example.org', repo_policy._stack_on)
452
3242.3.27 by Aaron Bentley
Interpret default stacking paths relative to config bzrdir
453
    def test_determine_stacking_policy_relative(self):
454
        parent_bzrdir = self.make_bzrdir('.')
455
        child_bzrdir = self.make_bzrdir('child')
456
        parent_bzrdir.get_config().set_default_stack_on('child2')
457
        repo_policy = child_bzrdir.determine_repository_policy()
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
458
        self.assertEqual('child2', repo_policy._stack_on)
459
        self.assertEqual(parent_bzrdir.root_transport.base,
460
                         repo_policy._stack_on_pwd)
3242.3.27 by Aaron Bentley
Interpret default stacking paths relative to config bzrdir
461
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
462
    def prepare_default_stacking(self, child_format='1.6'):
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
463
        parent_bzrdir = self.make_bzrdir('.')
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
464
        child_branch = self.make_branch('child', format=child_format)
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
465
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
466
        new_child_transport = parent_bzrdir.transport.clone('child2')
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
467
        return child_branch, new_child_transport
468
469
    def test_clone_on_transport_obeys_stacking_policy(self):
470
        child_branch, new_child_transport = self.prepare_default_stacking()
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
471
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
472
        self.assertEqual(child_branch.base,
3537.3.5 by Martin Pool
merge trunk including stacking policy
473
                         new_child.open_branch().get_stacked_on_url())
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
474
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
475
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
476
        # Make stackable source branch with an unstackable repo format.
477
        source_bzrdir = self.make_bzrdir('source')
478
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
479
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
480
            source_bzrdir)
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
481
        # Make a directory with a default stacking policy
482
        parent_bzrdir = self.make_bzrdir('parent')
483
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
484
        parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
485
        # Clone source into directory
486
        target = source_bzrdir.clone(self.get_url('parent/target'))
487
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
488
    def test_sprout_obeys_stacking_policy(self):
489
        child_branch, new_child_transport = self.prepare_default_stacking()
490
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
491
        self.assertEqual(child_branch.base,
3537.3.5 by Martin Pool
merge trunk including stacking policy
492
                         new_child.open_branch().get_stacked_on_url())
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
493
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
494
    def test_clone_ignores_policy_for_unsupported_formats(self):
495
        child_branch, new_child_transport = self.prepare_default_stacking(
496
            child_format='pack-0.92')
497
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
498
        self.assertRaises(errors.UnstackableBranchFormat,
499
                          new_child.open_branch().get_stacked_on_url)
500
501
    def test_sprout_ignores_policy_for_unsupported_formats(self):
502
        child_branch, new_child_transport = self.prepare_default_stacking(
503
            child_format='pack-0.92')
504
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
505
        self.assertRaises(errors.UnstackableBranchFormat,
506
                          new_child.open_branch().get_stacked_on_url)
507
508
    def test_sprout_upgrades_format_if_stacked_specified(self):
509
        child_branch, new_child_transport = self.prepare_default_stacking(
510
            child_format='pack-0.92')
511
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
512
                                               stacked=True)
513
        self.assertEqual(child_branch.bzrdir.root_transport.base,
514
                         new_child.open_branch().get_stacked_on_url())
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
515
        repo = new_child.open_repository()
516
        self.assertTrue(repo._format.supports_external_lookups)
517
        self.assertFalse(repo.supports_rich_root())
518
3650.5.1 by Aaron Bentley
Fix push to use clone all the time.
519
    def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
520
        child_branch, new_child_transport = self.prepare_default_stacking(
521
            child_format='pack-0.92')
522
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
523
            stacked_on=child_branch.bzrdir.root_transport.base)
524
        self.assertEqual(child_branch.bzrdir.root_transport.base,
525
                         new_child.open_branch().get_stacked_on_url())
526
        repo = new_child.open_repository()
527
        self.assertTrue(repo._format.supports_external_lookups)
528
        self.assertFalse(repo.supports_rich_root())
529
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
530
    def test_sprout_upgrades_to_rich_root_format_if_needed(self):
531
        child_branch, new_child_transport = self.prepare_default_stacking(
532
            child_format='rich-root-pack')
3665.2.3 by John Arbash Meinel
Fix a test that was expected to fail.
533
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
534
                                               stacked=True)
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
535
        repo = new_child.open_repository()
536
        self.assertTrue(repo._format.supports_external_lookups)
537
        self.assertTrue(repo.supports_rich_root())
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
538
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
539
    def test_add_fallback_repo_handles_absolute_urls(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
540
        stack_on = self.make_branch('stack_on', format='1.6')
541
        repo = self.make_repository('repo', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
542
        policy = bzrdir.UseExistingRepository(repo, stack_on.base)
543
        policy._add_fallback(repo)
544
545
    def test_add_fallback_repo_handles_relative_urls(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
546
        stack_on = self.make_branch('stack_on', format='1.6')
547
        repo = self.make_repository('repo', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
548
        policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
549
        policy._add_fallback(repo)
550
551
    def test_configure_relative_branch_stacking_url(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
552
        stack_on = self.make_branch('stack_on', format='1.6')
553
        stacked = self.make_branch('stack_on/stacked', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
554
        policy = bzrdir.UseExistingRepository(stacked.repository,
555
            '.', stack_on.base)
556
        policy.configure_branch(stacked)
3537.3.5 by Martin Pool
merge trunk including stacking policy
557
        self.assertEqual('..', stacked.get_stacked_on_url())
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
558
559
    def test_relative_branch_stacking_to_absolute(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
560
        stack_on = self.make_branch('stack_on', format='1.6')
561
        stacked = self.make_branch('stack_on/stacked', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
562
        policy = bzrdir.UseExistingRepository(stacked.repository,
563
            '.', self.get_readonly_url('stack_on'))
564
        policy.configure_branch(stacked)
565
        self.assertEqual(self.get_readonly_url('stack_on'),
3537.3.5 by Martin Pool
merge trunk including stacking policy
566
                         stacked.get_stacked_on_url())
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
567
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
568
1534.4.39 by Robert Collins
Basic BzrDir support.
569
class ChrootedTests(TestCaseWithTransport):
570
    """A support class that provides readonly urls outside the local namespace.
571
572
    This is done by checking if self.transport_server is a MemoryServer. if it
573
    is then we are chrooted already, if it is not then an HttpServer is used
574
    for readonly urls.
575
    """
576
577
    def setUp(self):
578
        super(ChrootedTests, self).setUp()
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
579
        if not self.vfs_transport_factory == memory.MemoryServer:
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
580
            self.transport_readonly_server = http_server.HttpServer
1534.4.39 by Robert Collins
Basic BzrDir support.
581
3015.3.45 by Daniel Watkins
Extract common method.
582
    def local_branch_path(self, branch):
583
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
584
1534.4.39 by Robert Collins
Basic BzrDir support.
585
    def test_open_containing(self):
586
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
587
                          self.get_readonly_url(''))
588
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
589
                          self.get_readonly_url('g/p/q'))
590
        control = bzrdir.BzrDir.create(self.get_url())
591
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
592
        self.assertEqual('', relpath)
593
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
594
        self.assertEqual('g/p/q', relpath)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
595
3015.3.46 by Daniel Watkins
Made tests more granular.
596
    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.
597
        self.assertRaises(errors.NotBranchError,
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
598
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
599
            self.get_readonly_url(''))
600
3015.3.46 by Daniel Watkins
Made tests more granular.
601
    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.
602
        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.
603
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
604
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
605
                'topdir/foo')
606
        self.assertEqual(os.path.realpath('topdir'),
607
                         os.path.realpath(tree.basedir))
608
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
609
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
610
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
611
            osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
612
            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.
613
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
614
3015.3.46 by Daniel Watkins
Made tests more granular.
615
    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.
616
        self.make_branch('branch')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
617
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
618
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
619
                'branch/foo')
620
        self.assertEqual(tree, None)
621
        self.assertEqual(os.path.realpath('branch'),
3015.3.45 by Daniel Watkins
Extract common method.
622
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
623
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
624
            osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
625
            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.
626
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
627
3015.3.46 by Daniel Watkins
Made tests more granular.
628
    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.
629
        self.make_repository('repo')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
630
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
631
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
632
                'repo')
633
        self.assertEqual(tree, None)
634
        self.assertEqual(branch, None)
635
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
636
            osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
637
            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.
638
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
639
3015.3.46 by Daniel Watkins
Made tests more granular.
640
    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.
641
        self.make_repository('shared', shared=True)
642
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
643
                                                force_new_tree=False)
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
644
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
645
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
646
                'shared/branch')
647
        self.assertEqual(tree, None)
648
        self.assertEqual(os.path.realpath('shared/branch'),
3015.3.45 by Daniel Watkins
Extract common method.
649
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
650
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
651
            osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
652
            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.
653
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
654
3015.3.48 by Daniel Watkins
Further granulated tests.
655
    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.
656
        self.make_branch_and_tree('foo')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
657
        self.build_tree(['foo/bar/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
658
        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.
659
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
660
                'foo/bar')
661
        self.assertEqual(os.path.realpath('foo'),
662
                         os.path.realpath(tree.basedir))
663
        self.assertEqual(os.path.realpath('foo'),
3015.3.45 by Daniel Watkins
Extract common method.
664
                         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.
665
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
666
            osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
667
            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.
668
        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.
669
3015.3.48 by Daniel Watkins
Further granulated tests.
670
    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.
671
        self.make_repository('bar')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
672
        self.build_tree(['bar/baz/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
673
        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.
674
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
675
                'bar/baz')
676
        self.assertEqual(tree, None)
677
        self.assertEqual(branch, None)
678
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
679
            osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
680
            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.
681
        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.
682
1534.6.11 by Robert Collins
Review feedback.
683
    def test_open_containing_from_transport(self):
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
684
        self.assertRaises(NotBranchError,
685
            bzrdir.BzrDir.open_containing_from_transport,
686
            _mod_transport.get_transport(self.get_readonly_url('')))
687
        self.assertRaises(NotBranchError,
688
            bzrdir.BzrDir.open_containing_from_transport,
689
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
690
        control = bzrdir.BzrDir.create(self.get_url())
1534.6.11 by Robert Collins
Review feedback.
691
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
692
            _mod_transport.get_transport(self.get_readonly_url('')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
693
        self.assertEqual('', relpath)
1534.6.11 by Robert Collins
Review feedback.
694
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
695
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
696
        self.assertEqual('g/p/q', relpath)
697
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
698
    def test_open_containing_tree_or_branch(self):
699
        self.make_branch_and_tree('topdir')
700
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
701
            'topdir/foo')
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
702
        self.assertEqual(os.path.realpath('topdir'),
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
703
                         os.path.realpath(tree.basedir))
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
704
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
705
                         self.local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
706
        self.assertIs(tree.bzrdir, branch.bzrdir)
707
        self.assertEqual('foo', relpath)
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
708
        # opening from non-local should not return the tree
709
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
710
            self.get_readonly_url('topdir/foo'))
711
        self.assertEqual(None, tree)
712
        self.assertEqual('foo', relpath)
713
        # without a tree:
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
714
        self.make_branch('topdir/foo')
715
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
716
            'topdir/foo')
717
        self.assertIs(tree, None)
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
718
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
719
                         self.local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
720
        self.assertEqual('', relpath)
721
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
722
    def test_open_tree_or_branch(self):
723
        self.make_branch_and_tree('topdir')
724
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
725
        self.assertEqual(os.path.realpath('topdir'),
726
                         os.path.realpath(tree.basedir))
727
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
728
                         self.local_branch_path(branch))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
729
        self.assertIs(tree.bzrdir, branch.bzrdir)
730
        # opening from non-local should not return the tree
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
731
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
732
            self.get_readonly_url('topdir'))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
733
        self.assertEqual(None, tree)
734
        # without a tree:
735
        self.make_branch('topdir/foo')
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
736
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
737
        self.assertIs(tree, None)
738
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
739
                         self.local_branch_path(branch))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
740
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
741
    def test_open_from_transport(self):
742
        # transport pointing at bzrdir should give a bzrdir with root transport
743
        # set to the given transport
744
        control = bzrdir.BzrDir.create(self.get_url())
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
745
        t = self.get_transport()
746
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
747
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
748
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
749
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
750
    def test_open_from_transport_no_bzrdir(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
751
        t = self.get_transport()
752
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
753
754
    def test_open_from_transport_bzrdir_in_parent(self):
755
        control = bzrdir.BzrDir.create(self.get_url())
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
756
        t = self.get_transport()
757
        t.mkdir('subdir')
758
        t = t.clone('subdir')
759
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
760
2100.3.28 by Aaron Bentley
Make sprout recursive
761
    def test_sprout_recursive(self):
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
762
        tree = self.make_branch_and_tree('tree1',
763
                                         format='dirstate-with-subtree')
2100.3.28 by Aaron Bentley
Make sprout recursive
764
        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.
765
            format='dirstate-with-subtree')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
766
        sub_tree.set_root_id('subtree-root')
2100.3.28 by Aaron Bentley
Make sprout recursive
767
        tree.add_reference(sub_tree)
768
        self.build_tree(['tree1/subtree/file'])
769
        sub_tree.add('file')
770
        tree.commit('Initial commit')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
771
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
772
        tree2.lock_read()
773
        self.addCleanup(tree2.unlock)
2100.3.28 by Aaron Bentley
Make sprout recursive
774
        self.failUnlessExists('tree2/subtree/file')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
775
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
2100.3.28 by Aaron Bentley
Make sprout recursive
776
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
777
    def test_cloning_metadir(self):
778
        """Ensure that cloning metadir is suitable"""
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
779
        bzrdir = self.make_bzrdir('bzrdir')
780
        bzrdir.cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
781
        branch = self.make_branch('branch', format='knit')
782
        format = branch.bzrdir.cloning_metadir()
783
        self.assertIsInstance(format.workingtree_format,
2255.2.174 by Martin Pool
remove AB1 WorkingTree and experimental-knit3
784
            workingtree.WorkingTreeFormat3)
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
785
786
    def test_sprout_recursive_treeless(self):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
787
        tree = self.make_branch_and_tree('tree1',
788
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
789
        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.
790
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
791
        tree.add_reference(sub_tree)
792
        self.build_tree(['tree1/subtree/file'])
793
        sub_tree.add('file')
794
        tree.commit('Initial commit')
5409.1.20 by Vincent Ladeuil
Revert to 'conflict' being the default orphaning policy and fix fallouts.
795
        # The following line force the orhaning to reveal bug #634470
796
        tree.branch.get_config().set_user_option(
5409.1.24 by Vincent Ladeuil
Rename bzrlib.transform.orphan_policy to bzr.transform.orphan_policy.
797
            'bzr.transform.orphan_policy', 'move')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
798
        tree.bzrdir.destroy_workingtree()
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
799
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
800
        # fail :-( ) -- vila 20100909
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
801
        repo = self.make_repository('repo', shared=True,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
802
            format='dirstate-with-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
803
        repo.set_make_working_trees(False)
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
804
        # FIXME: we just deleted the workingtree and now we want to use it ????
805
        # At a minimum, we should use tree.branch below (but this fails too
806
        # currently) or stop calling this test 'treeless'. Specifically, I've
807
        # turn the line below into an assertRaises when 'subtree/.bzr' is
808
        # orphaned and sprout tries to access the branch there (which is left
809
        # by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
810
        # [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
811
        # #634470.  -- vila 20100909
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
812
        self.assertRaises(errors.NotBranchError,
813
                          tree.bzrdir.sprout, 'repo/tree2')
814
#        self.failUnlessExists('repo/tree2/subtree')
815
#        self.failIfExists('repo/tree2/subtree/file')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
816
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
817
    def make_foo_bar_baz(self):
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
818
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
819
        bar = self.make_branch('foo/bar').bzrdir
820
        baz = self.make_branch('baz').bzrdir
821
        return foo, bar, baz
822
823
    def test_find_bzrdirs(self):
824
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
825
        t = self.get_transport()
826
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
827
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
828
    def make_fake_permission_denied_transport(self, transport, paths):
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
829
        """Create a transport that raises PermissionDenied for some paths."""
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
830
        def filter(path):
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
831
            if path in paths:
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
832
                raise errors.PermissionDenied(path)
833
            return path
834
        path_filter_server = pathfilter.PathFilteringServer(transport, filter)
835
        path_filter_server.start_server()
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
836
        self.addCleanup(path_filter_server.stop_server)
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
837
        path_filter_transport = pathfilter.PathFilteringTransport(
838
            path_filter_server, '.')
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
839
        return (path_filter_server, path_filter_transport)
840
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
841
    def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
842
        """Check that each branch url ends with the given suffix."""
843
        for actual_bzrdir in actual_bzrdirs:
5215.3.5 by Marius Kruger
factor out _assert_branch_urls
844
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
845
846
    def test_find_bzrdirs_permission_denied(self):
847
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
848
        t = self.get_transport()
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
849
        path_filter_server, path_filter_transport = \
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
850
            self.make_fake_permission_denied_transport(t, ['foo'])
5215.3.5 by Marius Kruger
factor out _assert_branch_urls
851
        # local transport
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
852
        self.assertBranchUrlsEndWith('/baz/',
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
853
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
854
        # smart server
855
        smart_transport = self.make_smart_server('.',
856
            backing_server=path_filter_server)
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
857
        self.assertBranchUrlsEndWith('/baz/',
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
858
            bzrdir.BzrDir.find_bzrdirs(smart_transport))
5215.4.1 by Marius Kruger
BzrDir.find_branches should not fall over when encountering branches with missing repos
859
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
860
    def test_find_bzrdirs_list_current(self):
861
        def list_current(transport):
862
            return [s for s in transport.list_dir('') if s != 'baz']
863
864
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
865
        t = self.get_transport()
866
        self.assertEqualBzrdirs(
867
            [foo, bar],
868
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
869
870
    def test_find_bzrdirs_evaluate(self):
871
        def evaluate(bzrdir):
872
            try:
873
                repo = bzrdir.open_repository()
874
            except NoRepositoryPresent:
875
                return True, bzrdir.root_transport.base
876
            else:
877
                return False, bzrdir.root_transport.base
878
879
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
880
        t = self.get_transport()
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
881
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
882
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
883
884
    def assertEqualBzrdirs(self, first, second):
885
        first = list(first)
886
        second = list(second)
887
        self.assertEqual(len(first), len(second))
888
        for x, y in zip(first, second):
889
            self.assertEqual(x.root_transport.base, y.root_transport.base)
890
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
891
    def test_find_branches(self):
892
        root = self.make_repository('', shared=True)
893
        foo, bar, baz = self.make_foo_bar_baz()
894
        qux = self.make_bzrdir('foo/qux')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
895
        t = self.get_transport()
896
        branches = bzrdir.BzrDir.find_branches(t)
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
897
        self.assertEqual(baz.root_transport.base, branches[0].base)
898
        self.assertEqual(foo.root_transport.base, branches[1].base)
899
        self.assertEqual(bar.root_transport.base, branches[2].base)
900
901
        # ensure this works without a top-level repo
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
902
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
903
        self.assertEqual(foo.root_transport.base, branches[0].base)
904
        self.assertEqual(bar.root_transport.base, branches[1].base)
905
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
906
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
907
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
908
909
    def test_find_bzrdirs_missing_repo(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
910
        t = self.get_transport()
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
911
        arepo = self.make_repository('arepo', shared=True)
912
        abranch_url = arepo.user_url + '/abranch'
913
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
914
        t.delete_tree('arepo/.bzr')
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
915
        self.assertRaises(errors.NoRepositoryPresent,
916
            branch.Branch.open, abranch_url)
917
        self.make_branch('baz')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
918
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
919
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
920
921
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
922
class TestMeta1DirFormat(TestCaseWithTransport):
923
    """Tests specific to the meta1 dir format."""
924
925
    def test_right_base_dirs(self):
926
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
927
        t = dir.transport
928
        branch_base = t.clone('branch').base
929
        self.assertEqual(branch_base, dir.get_branch_transport(None).base)
930
        self.assertEqual(branch_base,
1508.1.25 by Robert Collins
Update per review comments.
931
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
932
        repository_base = t.clone('repository').base
933
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
934
        self.assertEqual(repository_base,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
935
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
936
        checkout_base = t.clone('checkout').base
937
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
938
        self.assertEqual(checkout_base,
939
                         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.
940
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
941
    def test_meta1dir_uses_lockdir(self):
942
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
943
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
944
        t = dir.transport
945
        self.assertIsDirectory('branch-lock', t)
946
2100.3.35 by Aaron Bentley
equality operations on bzrdir
947
    def test_comparison(self):
948
        """Equality and inequality behave properly.
949
950
        Metadirs should compare equal iff they have the same repo, branch and
951
        tree formats.
952
        """
953
        mydir = bzrdir.format_registry.make_bzrdir('knit')
954
        self.assertEqual(mydir, mydir)
955
        self.assertFalse(mydir != mydir)
956
        otherdir = bzrdir.format_registry.make_bzrdir('knit')
957
        self.assertEqual(otherdir, mydir)
958
        self.assertFalse(otherdir != mydir)
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
959
        otherdir2 = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
2100.3.35 by Aaron Bentley
equality operations on bzrdir
960
        self.assertNotEqual(otherdir2, mydir)
961
        self.assertFalse(otherdir2 == mydir)
962
2255.12.1 by Robert Collins
Implement upgrade for working trees.
963
    def test_needs_conversion_different_working_tree(self):
964
        # meta1dirs need an conversion if any element is not the default.
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
965
        new_format = bzrdir.format_registry.make_bzrdir('dirstate')
966
        tree = self.make_branch_and_tree('tree', format='knit')
967
        self.assertTrue(tree.bzrdir.needs_format_conversion(
968
            new_format))
2255.12.1 by Robert Collins
Implement upgrade for working trees.
969
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
970
    def test_initialize_on_format_uses_smart_transport(self):
971
        self.setup_smart_server_with_call_log()
972
        new_format = bzrdir.format_registry.make_bzrdir('dirstate')
973
        transport = self.get_transport('target')
974
        transport.ensure_base()
975
        self.reset_smart_call_log()
976
        instance = new_format.initialize_on_transport(transport)
977
        self.assertIsInstance(instance, remote.RemoteBzrDir)
978
        rpc_count = len(self.hpss_calls)
979
        # This figure represent the amount of work to perform this use case. It
980
        # is entirely ok to reduce this number if a test fails due to rpc_count
981
        # being too low. If rpc_count increases, more network roundtrips have
982
        # become necessary for this use case. Please do not adjust this number
983
        # upwards without agreement from bzr's network support maintainers.
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
984
        self.assertEqual(2, rpc_count)
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
985
2255.12.1 by Robert Collins
Implement upgrade for working trees.
986
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
987
class TestFormat5(TestCaseWithTransport):
988
    """Tests specific to the version 5 bzrdir format."""
989
990
    def test_same_lockfiles_between_tree_repo_branch(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
991
        # this checks that only a single lockfiles instance is created
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
992
        # for format 5 objects
993
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
994
        def check_dir_components_use_same_lock(dir):
995
            ctrl_1 = dir.open_repository().control_files
996
            ctrl_2 = dir.open_branch().control_files
997
            ctrl_3 = dir.open_workingtree()._control_files
998
            self.assertTrue(ctrl_1 is ctrl_2)
999
            self.assertTrue(ctrl_2 is ctrl_3)
1000
        check_dir_components_use_same_lock(dir)
1001
        # and if we open it normally.
1002
        dir = bzrdir.BzrDir.open(self.get_url())
1003
        check_dir_components_use_same_lock(dir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1004
1534.5.16 by Robert Collins
Review feedback.
1005
    def test_can_convert(self):
1006
        # format 5 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1007
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
1008
        self.assertTrue(dir.can_convert_format())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1009
1534.5.16 by Robert Collins
Review feedback.
1010
    def test_needs_conversion(self):
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1011
        # format 5 dirs need a conversion if they are not the default,
1012
        # and they aren't
1013
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1014
        # don't need to convert it to itself
1015
        self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
1016
        # do need to convert it to the current default
1017
        self.assertTrue(dir.needs_format_conversion(
1018
            bzrdir.BzrDirFormat.get_default_format()))
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1019
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
1020
1021
class TestFormat6(TestCaseWithTransport):
1022
    """Tests specific to the version 6 bzrdir format."""
1023
1024
    def test_same_lockfiles_between_tree_repo_branch(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1025
        # this checks that only a single lockfiles instance is created
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
1026
        # for format 6 objects
1027
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1028
        def check_dir_components_use_same_lock(dir):
1029
            ctrl_1 = dir.open_repository().control_files
1030
            ctrl_2 = dir.open_branch().control_files
1031
            ctrl_3 = dir.open_workingtree()._control_files
1032
            self.assertTrue(ctrl_1 is ctrl_2)
1033
            self.assertTrue(ctrl_2 is ctrl_3)
1034
        check_dir_components_use_same_lock(dir)
1035
        # and if we open it normally.
1036
        dir = bzrdir.BzrDir.open(self.get_url())
1037
        check_dir_components_use_same_lock(dir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1038
1534.5.16 by Robert Collins
Review feedback.
1039
    def test_can_convert(self):
1040
        # format 6 dirs are convertable
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1041
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1534.5.16 by Robert Collins
Review feedback.
1042
        self.assertTrue(dir.can_convert_format())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1043
1534.5.16 by Robert Collins
Review feedback.
1044
    def test_needs_conversion(self):
1045
        # format 6 dirs need an conversion if they are not the default.
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1046
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1047
        self.assertTrue(dir.needs_format_conversion(
1048
            bzrdir.BzrDirFormat.get_default_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.
1049
1050
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1051
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1052
    """A non .bzr based control directory."""
1053
1054
    def __init__(self, transport, format):
1055
        self._format = format
1056
        self.root_transport = transport
1057
        self.transport = transport.clone('.not')
1058
1059
1060
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1061
    """A test class representing any non-.bzr based disk format."""
1062
1063
    def initialize_on_transport(self, transport):
1064
        """Initialize a new .not dir in the base directory of a Transport."""
1065
        transport.mkdir('.not')
1066
        return self.open(transport)
1067
1068
    def open(self, transport):
1069
        """Open this directory."""
1070
        return NotBzrDir(transport, self)
1071
1072
    @classmethod
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1073
    def _known_formats(self):
1074
        return set([NotBzrDirFormat()])
1075
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
1076
1077
class NotBzrDirProber(controldir.Prober):
1078
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1079
    def probe_transport(self, transport):
1080
        """Our format is present if the transport ends in '.not/'."""
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
1081
        if transport.has('.not'):
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1082
            return NotBzrDirFormat()
1083
1084
1085
class TestNotBzrDir(TestCaseWithTransport):
1086
    """Tests for using the bzrdir api with a non .bzr based disk format.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1087
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1088
    If/when one of these is in the core, we can let the implementation tests
1089
    verify this works.
1090
    """
1091
1092
    def test_create_and_find_format(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1093
        # create a .notbzr dir
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1094
        format = NotBzrDirFormat()
1095
        dir = format.initialize(self.get_url())
1096
        self.assertIsInstance(dir, NotBzrDir)
1097
        # now probe for it.
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
1098
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1099
        try:
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1100
            found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1733.1.2 by Robert Collins
bugfix test for non .bzrdir support.
1101
            self.assertIsInstance(found, NotBzrDirFormat)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1102
        finally:
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
1103
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1104
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1105
    def test_included_in_known_formats(self):
5363.2.7 by Jelmer Vernooij
Fix tests.
1106
        not_format = NotBzrDirFormat()
1107
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1108
        try:
1109
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1110
            for format in formats:
1111
                if isinstance(format, NotBzrDirFormat):
1112
                    return
1113
            self.fail("No NotBzrDirFormat in %s" % formats)
1114
        finally:
5363.2.7 by Jelmer Vernooij
Fix tests.
1115
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1116
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1117
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.
1118
class NonLocalTests(TestCaseWithTransport):
1119
    """Tests for bzrdir static behaviour on non local paths."""
1120
1121
    def setUp(self):
1122
        super(NonLocalTests, self).setUp()
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
1123
        self.vfs_transport_factory = memory.MemoryServer
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1124
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.
1125
    def test_create_branch_convenience(self):
1126
        # 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
1127
        format = bzrdir.format_registry.make_bzrdir('knit')
1128
        branch = bzrdir.BzrDir.create_branch_convenience(
1129
            self.get_url('foo'), format=format)
1130
        self.assertRaises(errors.NoWorkingTree,
1131
                          branch.bzrdir.open_workingtree)
1132
        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.
1133
1134
    def test_create_branch_convenience_force_tree_not_local_fails(self):
1135
        # 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
1136
        format = bzrdir.format_registry.make_bzrdir('knit')
1137
        self.assertRaises(errors.NotLocalUrl,
1138
            bzrdir.BzrDir.create_branch_convenience,
1139
            self.get_url('foo'),
1140
            force_new_tree=True,
1141
            format=format)
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1142
        t = self.get_transport()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1143
        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.
1144
1563.2.38 by Robert Collins
make push preserve tree formats.
1145
    def test_clone(self):
1146
        # clone into a nonlocal path works
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1147
        format = bzrdir.format_registry.make_bzrdir('knit')
1148
        branch = bzrdir.BzrDir.create_branch_convenience('local',
1149
                                                         format=format)
1563.2.38 by Robert Collins
make push preserve tree formats.
1150
        branch.bzrdir.open_workingtree()
1151
        result = branch.bzrdir.clone(self.get_url('remote'))
1152
        self.assertRaises(errors.NoWorkingTree,
1153
                          result.open_workingtree)
1154
        result.open_branch()
1155
        result.open_repository()
1156
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
1157
    def test_checkout_metadir(self):
1158
        # checkout_metadir has reasonable working tree format even when no
1159
        # working tree is present
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1160
        self.make_branch('branch-knit2', format='dirstate-with-subtree')
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
1161
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1162
        checkout_format = my_bzrdir.checkout_metadir()
1163
        self.assertIsInstance(checkout_format.workingtree_format,
1164
                              workingtree.WorkingTreeFormat3)
2100.3.22 by Aaron Bentley
merge from bzr.dev
1165
2215.3.5 by Aaron Bentley
Add support for remote ls
1166
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1167
class TestHTTPRedirections(object):
1168
    """Test redirection between two http servers.
2164.2.16 by Vincent Ladeuil
Add tests.
1169
1170
    This MUST be used by daughter classes that also inherit from
1171
    TestCaseWithTwoWebservers.
1172
1173
    We can't inherit directly from TestCaseWithTwoWebservers or the
1174
    test framework will try to create an instance which cannot
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1175
    run, its implementation being incomplete.
2164.2.16 by Vincent Ladeuil
Add tests.
1176
    """
1177
1178
    def create_transport_readonly_server(self):
5273.1.4 by Vincent Ladeuil
The default http protocol version wasn't properly defined and as such not respected by some parametrized tests.
1179
        # We don't set the http protocol version, relying on the default
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1180
        return http_utils.HTTPServerRedirecting()
2164.2.16 by Vincent Ladeuil
Add tests.
1181
1182
    def create_transport_secondary_server(self):
5273.1.4 by Vincent Ladeuil
The default http protocol version wasn't properly defined and as such not respected by some parametrized tests.
1183
        # We don't set the http protocol version, relying on the default
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1184
        return http_utils.HTTPServerRedirecting()
2164.2.16 by Vincent Ladeuil
Add tests.
1185
1186
    def setUp(self):
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1187
        super(TestHTTPRedirections, self).setUp()
2164.2.16 by Vincent Ladeuil
Add tests.
1188
        # The redirections will point to the new server
1189
        self.new_server = self.get_readonly_server()
1190
        # The requests to the old server will be redirected
1191
        self.old_server = self.get_secondary_server()
1192
        # Configure the redirections
1193
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1194
1195
    def test_loop(self):
1196
        # Both servers redirect to each other creating a loop
2164.2.16 by Vincent Ladeuil
Add tests.
1197
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
1198
        # Starting from either server should loop
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1199
        old_url = self._qualified_url(self.old_server.host,
2164.2.16 by Vincent Ladeuil
Add tests.
1200
                                      self.old_server.port)
1201
        oldt = self._transport(old_url)
1202
        self.assertRaises(errors.NotBranchError,
1203
                          bzrdir.BzrDir.open_from_transport, oldt)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1204
        new_url = self._qualified_url(self.new_server.host,
2164.2.16 by Vincent Ladeuil
Add tests.
1205
                                      self.new_server.port)
1206
        newt = self._transport(new_url)
1207
        self.assertRaises(errors.NotBranchError,
1208
                          bzrdir.BzrDir.open_from_transport, newt)
1209
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1210
    def test_qualifier_preserved(self):
1211
        wt = self.make_branch_and_tree('branch')
1212
        old_url = self._qualified_url(self.old_server.host,
1213
                                      self.old_server.port)
1214
        start = self._transport(old_url).clone('branch')
1215
        bdir = bzrdir.BzrDir.open_from_transport(start)
1216
        # Redirection should preserve the qualifier, hence the transport class
1217
        # itself.
1218
        self.assertIsInstance(bdir.root_transport, type(start))
1219
1220
1221
class TestHTTPRedirections_urllib(TestHTTPRedirections,
1222
                                  http_utils.TestCaseWithTwoWebservers):
2164.2.16 by Vincent Ladeuil
Add tests.
1223
    """Tests redirections for urllib implementation"""
1224
1225
    _transport = HttpTransport_urllib
1226
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1227
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1228
        result = 'http+urllib://%s:%s' % (host, port)
1229
        self.permit_url(result)
1230
        return result
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1231
2164.2.16 by Vincent Ladeuil
Add tests.
1232
1233
1234
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1235
                                  TestHTTPRedirections,
1236
                                  http_utils.TestCaseWithTwoWebservers):
2164.2.16 by Vincent Ladeuil
Add tests.
1237
    """Tests redirections for pycurl implementation"""
1238
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1239
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1240
        result = 'http+pycurl://%s:%s' % (host, port)
1241
        self.permit_url(result)
1242
        return result
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1243
1244
1245
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1246
                                  http_utils.TestCaseWithTwoWebservers):
1247
    """Tests redirections for the nosmart decorator"""
1248
1249
    _transport = NoSmartTransportDecorator
1250
1251
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1252
        result = 'nosmart+http://%s:%s' % (host, port)
1253
        self.permit_url(result)
1254
        return result
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1255
1256
1257
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1258
                                    http_utils.TestCaseWithTwoWebservers):
1259
    """Tests redirections for readonly decoratror"""
1260
1261
    _transport = ReadonlyTransportDecorator
1262
1263
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1264
        result = 'readonly+http://%s:%s' % (host, port)
1265
        self.permit_url(result)
1266
        return result
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1267
1268
1269
class TestDotBzrHidden(TestCaseWithTransport):
1270
3023.1.3 by Alexander Belchenko
John's review
1271
    ls = ['ls']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1272
    if sys.platform == 'win32':
3023.1.3 by Alexander Belchenko
John's review
1273
        ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1274
1275
    def get_ls(self):
3023.1.3 by Alexander Belchenko
John's review
1276
        f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
1277
            stderr=subprocess.PIPE)
1278
        out, err = f.communicate()
1279
        self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1280
                         % (self.ls, err))
1281
        return out.splitlines()
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1282
1283
    def test_dot_bzr_hidden(self):
3023.1.2 by Alexander Belchenko
Martin's review.
1284
        if sys.platform == 'win32' and not win32utils.has_win32file:
1285
            raise TestSkipped('unable to make file hidden without pywin32 library')
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1286
        b = bzrdir.BzrDir.create('.')
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
1287
        self.build_tree(['a'])
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1288
        self.assertEquals(['a'], self.get_ls())
1289
1290
    def test_dot_bzr_hidden_with_url(self):
3023.1.2 by Alexander Belchenko
Martin's review.
1291
        if sys.platform == 'win32' and not win32utils.has_win32file:
1292
            raise TestSkipped('unable to make file hidden without pywin32 library')
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1293
        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
1294
        self.build_tree(['a'])
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1295
        self.assertEquals(['a'], self.get_ls())
3583.1.2 by Andrew Bennetts
Add test for fix.
1296
1297
1298
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1299
    """Test BzrDirFormat implementation for TestBzrDirSprout."""
1300
1301
    def _open(self, transport):
1302
        return _TestBzrDir(transport, self)
1303
1304
1305
class _TestBzrDir(bzrdir.BzrDirMeta1):
1306
    """Test BzrDir implementation for TestBzrDirSprout.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1307
3583.1.2 by Andrew Bennetts
Add test for fix.
1308
    When created a _TestBzrDir already has repository and a branch.  The branch
1309
    is a test double as well.
1310
    """
1311
1312
    def __init__(self, *args, **kwargs):
1313
        super(_TestBzrDir, self).__init__(*args, **kwargs)
1314
        self.test_branch = _TestBranch()
1315
        self.test_branch.repository = self.create_repository()
1316
1317
    def open_branch(self, unsupported=False):
1318
        return self.test_branch
1319
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
1320
    def cloning_metadir(self, require_stacking=False):
3583.1.2 by Andrew Bennetts
Add test for fix.
1321
        return _TestBzrDirFormat()
1322
1323
4086.1.3 by Andrew Bennetts
Fix bzrlib.tests.test_bzrdir.
1324
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1325
    """Test Branch format for TestBzrDirSprout."""
1326
1327
3583.1.2 by Andrew Bennetts
Add test for fix.
1328
class _TestBranch(bzrlib.branch.Branch):
1329
    """Test Branch implementation for TestBzrDirSprout."""
1330
1331
    def __init__(self, *args, **kwargs):
4086.1.3 by Andrew Bennetts
Fix bzrlib.tests.test_bzrdir.
1332
        self._format = _TestBranchFormat()
3583.1.2 by Andrew Bennetts
Add test for fix.
1333
        super(_TestBranch, self).__init__(*args, **kwargs)
1334
        self.calls = []
3650.3.7 by Aaron Bentley
Fix test
1335
        self._parent = None
1336
3583.1.2 by Andrew Bennetts
Add test for fix.
1337
    def sprout(self, *args, **kwargs):
1338
        self.calls.append('sprout')
3650.3.7 by Aaron Bentley
Fix test
1339
        return _TestBranch()
3583.1.2 by Andrew Bennetts
Add test for fix.
1340
3650.3.4 by Aaron Bentley
Update test to permit calling copy_content_into
1341
    def copy_content_into(self, destination, revision_id=None):
1342
        self.calls.append('copy_content_into')
1343
3650.3.7 by Aaron Bentley
Fix test
1344
    def get_parent(self):
1345
        return self._parent
1346
1347
    def set_parent(self, parent):
1348
        self._parent = parent
1349
5536.1.13 by Andrew Bennetts
Fix a test failure (_TestBranch needs to implement lock_read/unlock).
1350
    def lock_read(self):
1351
        return lock.LogicalLockResult(self.unlock)
1352
1353
    def unlock(self):
1354
        return
1355
3583.1.2 by Andrew Bennetts
Add test for fix.
1356
1357
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1358
1359
    def test_sprout_uses_branch_sprout(self):
1360
        """BzrDir.sprout calls Branch.sprout.
1361
1362
        Usually, BzrDir.sprout should delegate to the branch's sprout method
1363
        for part of the work.  This allows the source branch to control the
1364
        choice of format for the new branch.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1365
3583.1.2 by Andrew Bennetts
Add test for fix.
1366
        There are exceptions, but this tests avoids them:
1367
          - if there's no branch in the source bzrdir,
1368
          - or if the stacking has been requested and the format needs to be
1369
            overridden to satisfy that.
1370
        """
1371
        # Make an instrumented bzrdir.
1372
        t = self.get_transport('source')
1373
        t.ensure_base()
1374
        source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1375
        # The instrumented bzrdir has a test_branch attribute that logs calls
1376
        # made to the branch contained in that bzrdir.  Initially the test
1377
        # branch exists but no calls have been made to it.
1378
        self.assertEqual([], source_bzrdir.test_branch.calls)
1379
1380
        # Sprout the bzrdir
1381
        target_url = self.get_url('target')
1382
        result = source_bzrdir.sprout(target_url, recurse='no')
1383
1384
        # The bzrdir called the branch's sprout method.
3650.3.4 by Aaron Bentley
Update test to permit calling copy_content_into
1385
        self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
3650.3.5 by Aaron Bentley
Fix parent location when copying content
1386
1387
    def test_sprout_parent(self):
1388
        grandparent_tree = self.make_branch('grandparent')
1389
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1390
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1391
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
4160.1.1 by Robert Collins
Add a BzrDir.pre_open hook for use by the smart server gaol.
1392
1393
1394
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1395
1396
    def test_pre_open_called(self):
1397
        calls = []
1398
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1399
        transport = self.get_transport('foo')
1400
        url = transport.base
1401
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1402
        self.assertEqual([transport.base], [t.base for t in calls])
1403
1404
    def test_pre_open_actual_exceptions_raised(self):
1405
        count = [0]
1406
        def fail_once(transport):
1407
            count[0] += 1
1408
            if count[0] == 1:
1409
                raise errors.BzrError("fail")
1410
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1411
        transport = self.get_transport('foo')
1412
        url = transport.base
1413
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1414
        self.assertEqual('fail', err._preformatted_string)
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1415
1416
    def test_post_repo_init(self):
1417
        from bzrlib.bzrdir import RepoInitHookParams
1418
        calls = []
5107.3.4 by Marco Pantaleoni
Applied suggestions from merge reviewer (John A Meinel):
1419
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1420
            calls.append, None)
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1421
        self.make_repository('foo')
1422
        self.assertLength(1, calls)
1423
        params = calls[0]
1424
        self.assertIsInstance(params, RepoInitHookParams)
1425
        self.assertTrue(hasattr(params, 'bzrdir'))
1426
        self.assertTrue(hasattr(params, 'repository'))
5050.21.3 by Andrew Bennetts
Add a test for RepoInitHookParams.__repr__ too.
1427
1428
    def test_post_repo_init_hook_repr(self):
1429
        param_reprs = []
1430
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1431
            lambda params: param_reprs.append(repr(params)), None)
1432
        self.make_repository('foo')
1433
        self.assertLength(1, param_reprs)
1434
        param_repr = param_reprs[0]
1435
        self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1436
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1437
1438
class TestGenerateBackupName(TestCaseWithMemoryTransport):
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1439
    # FIXME: This may need to be unified with test_osutils.TestBackupNames or
1440
    # moved to per_bzrdir or per_transport for better coverage ?
1441
    # -- vila 20100909
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1442
1443
    def setUp(self):
1444
        super(TestGenerateBackupName, self).setUp()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1445
        self._transport = self.get_transport()
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1446
        bzrdir.BzrDir.create(self.get_url(),
1447
            possible_transports=[self._transport])
1448
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1449
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1450
    def test_deprecated_generate_backup_name(self):
1451
        res = self.applyDeprecated(
1452
                symbol_versioning.deprecated_in((2, 3, 0)),
1453
                self._bzrdir.generate_backup_name, 'whatever')
1454
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1455
    def test_new(self):
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1456
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1457
1458
    def test_exiting(self):
1459
        self._transport.put_bytes("a.~1~", "some content")
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1460
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))