/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_info.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 00:00:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6672.
  • Revision ID: jelmer@jelmer.uk-20170608000028-e3ggtt4wjbcjh91j
Drop pycurl support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007-2012 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import sys
 
18
 
 
19
from .. import (
 
20
    branch as _mod_branch,
 
21
    bzrbranch as _mod_bzrbranch,
 
22
    controldir,
 
23
    info,
 
24
    tests,
 
25
    workingtree,
 
26
    repository as _mod_repository,
 
27
    )
 
28
 
 
29
 
 
30
class TestInfo(tests.TestCaseWithTransport):
 
31
 
 
32
    def test_describe_standalone_layout(self):
 
33
        tree = self.make_branch_and_tree('tree')
 
34
        self.assertEqual('Empty control directory', info.describe_layout())
 
35
        self.assertEqual(
 
36
            'Unshared repository with trees and colocated branches',
 
37
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
 
38
        tree.branch.repository.set_make_working_trees(False)
 
39
        self.assertEqual('Unshared repository with colocated branches',
 
40
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
 
41
        self.assertEqual('Standalone branch',
 
42
            info.describe_layout(tree.branch.repository, tree.branch,
 
43
                control=tree.bzrdir))
 
44
        self.assertEqual('Standalone branchless tree',
 
45
            info.describe_layout(tree.branch.repository, None, tree,
 
46
                control=tree.bzrdir))
 
47
        self.assertEqual('Standalone tree',
 
48
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
49
                control=tree.bzrdir))
 
50
        tree.branch.bind(tree.branch)
 
51
        self.assertEqual('Bound branch',
 
52
            info.describe_layout(tree.branch.repository, tree.branch,
 
53
                control=tree.bzrdir))
 
54
        self.assertEqual('Checkout',
 
55
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
56
                control=tree.bzrdir))
 
57
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
58
        self.assertEqual('Lightweight checkout',
 
59
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
60
                                 checkout, control=tree.bzrdir))
 
61
 
 
62
    def test_describe_repository_layout(self):
 
63
        repository = self.make_repository('.', shared=True)
 
64
        tree = controldir.ControlDir.create_branch_convenience('tree',
 
65
            force_new_tree=True).bzrdir.open_workingtree()
 
66
        self.assertEqual('Shared repository with trees and colocated branches',
 
67
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
 
68
        repository.set_make_working_trees(False)
 
69
        self.assertEqual('Shared repository with colocated branches',
 
70
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
 
71
        self.assertEqual('Repository branch',
 
72
            info.describe_layout(tree.branch.repository, tree.branch,
 
73
                control=tree.bzrdir))
 
74
        self.assertEqual('Repository branchless tree',
 
75
            info.describe_layout(tree.branch.repository, None, tree,
 
76
                control=tree.bzrdir))
 
77
        self.assertEqual('Repository tree',
 
78
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
79
                control=tree.bzrdir))
 
80
        tree.branch.bind(tree.branch)
 
81
        self.assertEqual('Repository checkout',
 
82
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
83
                control=tree.bzrdir))
 
84
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
85
        self.assertEqual('Lightweight checkout',
 
86
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
87
                                 checkout, control=tree.bzrdir))
 
88
 
 
89
    def assertTreeDescription(self, format):
 
90
        """Assert a tree's format description matches expectations"""
 
91
        self.make_branch_and_tree('%s_tree' % format, format=format)
 
92
        tree = workingtree.WorkingTree.open('%s_tree' % format)
 
93
        self.assertEqual(format, info.describe_format(tree.bzrdir,
 
94
            tree.branch.repository, tree.branch, tree))
 
95
 
 
96
    def assertCheckoutDescription(self, format, expected=None):
 
97
        """Assert a checkout's format description matches expectations"""
 
98
        if expected is None:
 
99
            expected = format
 
100
        branch = self.make_branch('%s_cobranch' % format, format=format)
 
101
        # this ought to be easier...
 
102
        branch.create_checkout('%s_co' % format,
 
103
            lightweight=True).bzrdir.destroy_workingtree()
 
104
        control = controldir.ControlDir.open('%s_co' % format)
 
105
        old_format = control._format.workingtree_format
 
106
        try:
 
107
            control._format.workingtree_format = \
 
108
                controldir.format_registry.make_bzrdir(format).workingtree_format
 
109
            control.create_workingtree()
 
110
            tree = workingtree.WorkingTree.open('%s_co' % format)
 
111
            format_description = info.describe_format(tree.bzrdir,
 
112
                    tree.branch.repository, tree.branch, tree)
 
113
            self.assertEqual(expected, format_description,
 
114
                "checkout of format called %r was described as %r" %
 
115
                (expected, format_description))
 
116
        finally:
 
117
            control._format.workingtree_format = old_format
 
118
 
 
119
    def assertBranchDescription(self, format, expected=None):
 
120
        """Assert branch's format description matches expectations"""
 
121
        if expected is None:
 
122
            expected = format
 
123
        self.make_branch('%s_branch' % format, format=format)
 
124
        branch = _mod_branch.Branch.open('%s_branch' % format)
 
125
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
 
126
            branch.repository, branch, None))
 
127
 
 
128
    def assertRepoDescription(self, format, expected=None):
 
129
        """Assert repository's format description matches expectations"""
 
130
        if expected is None:
 
131
            expected = format
 
132
        self.make_repository('%s_repo' % format, format=format)
 
133
        repo = _mod_repository.Repository.open('%s_repo' % format)
 
134
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
 
135
            repo, None, None))
 
136
 
 
137
    def test_describe_tree_format(self):
 
138
        for key in controldir.format_registry.keys():
 
139
            if key in controldir.format_registry.aliases():
 
140
                continue
 
141
            self.assertTreeDescription(key)
 
142
 
 
143
    def test_describe_checkout_format(self):
 
144
        for key in controldir.format_registry.keys():
 
145
            if key in controldir.format_registry.aliases():
 
146
                # Aliases will not describe correctly in the UI because the
 
147
                # real format is found.
 
148
                continue
 
149
            # legacy: weave does not support checkouts
 
150
            if key == 'weave':
 
151
                continue
 
152
            if controldir.format_registry.get_info(key).experimental:
 
153
                # We don't require that experimental formats support checkouts
 
154
                # or describe correctly in the UI.
 
155
                continue
 
156
            if controldir.format_registry.get_info(key).hidden:
 
157
                continue
 
158
            expected = None
 
159
            if key in ('pack-0.92',):
 
160
                expected = 'pack-0.92'
 
161
            elif key in ('knit', 'metaweave'):
 
162
                if 'metaweave' in controldir.format_registry:
 
163
                    expected = 'knit or metaweave'
 
164
                else:
 
165
                    expected = 'knit'
 
166
            elif key in ('1.14', '1.14-rich-root'):
 
167
                expected = '1.14 or 1.14-rich-root'
 
168
            self.assertCheckoutDescription(key, expected)
 
169
 
 
170
    def test_describe_branch_format(self):
 
171
        for key in controldir.format_registry.keys():
 
172
            if key in controldir.format_registry.aliases():
 
173
                continue
 
174
            if controldir.format_registry.get_info(key).hidden:
 
175
                continue
 
176
            expected = None
 
177
            if key in ('dirstate', 'knit'):
 
178
                expected = 'dirstate or knit'
 
179
            elif key in ('1.14',):
 
180
                expected = '1.14'
 
181
            elif key in ('1.14-rich-root',):
 
182
                expected = '1.14-rich-root'
 
183
            self.assertBranchDescription(key, expected)
 
184
 
 
185
    def test_describe_repo_format(self):
 
186
        for key in controldir.format_registry.keys():
 
187
            if key in controldir.format_registry.aliases():
 
188
                continue
 
189
            if controldir.format_registry.get_info(key).hidden:
 
190
                continue
 
191
            expected = None
 
192
            if key in ('dirstate', 'knit', 'dirstate-tags'):
 
193
                expected = 'dirstate or dirstate-tags or knit'
 
194
            elif key in ('1.14',):
 
195
                expected = '1.14'
 
196
            elif key in ('1.14-rich-root',):
 
197
                expected = '1.14-rich-root'
 
198
            self.assertRepoDescription(key, expected)
 
199
 
 
200
        format = controldir.format_registry.make_bzrdir('knit')
 
201
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
 
202
        tree = self.make_branch_and_tree('unknown', format=format)
 
203
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
 
204
            tree.branch.repository, tree.branch, tree))
 
205
 
 
206
    def test_gather_location_controldir_only(self):
 
207
        bzrdir = self.make_bzrdir('.')
 
208
        self.assertEqual([('control directory', bzrdir.user_url)],
 
209
            info.gather_location_info(control=bzrdir))
 
210
 
 
211
    def test_gather_location_standalone(self):
 
212
        tree = self.make_branch_and_tree('tree')
 
213
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
 
214
            info.gather_location_info(
 
215
                tree.branch.repository, tree.branch, tree, control=tree.bzrdir))
 
216
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
 
217
            info.gather_location_info(
 
218
                tree.branch.repository, tree.branch, control=tree.bzrdir))
 
219
        return tree
 
220
 
 
221
    def test_gather_location_repo(self):
 
222
        srepo = self.make_repository('shared', shared=True)
 
223
        self.assertEqual(
 
224
            [('shared repository', srepo.bzrdir.root_transport.base)],
 
225
            info.gather_location_info(srepo, control=srepo.bzrdir))
 
226
        urepo = self.make_repository('unshared')
 
227
        self.assertEqual(
 
228
            [('repository', urepo.bzrdir.root_transport.base)],
 
229
            info.gather_location_info(urepo, control=urepo.bzrdir))
 
230
 
 
231
    def test_gather_location_repo_branch(self):
 
232
        srepo = self.make_repository('shared', shared=True)
 
233
        self.assertEqual(
 
234
            [('shared repository', srepo.bzrdir.root_transport.base)],
 
235
            info.gather_location_info(srepo, control=srepo.bzrdir))
 
236
        tree = self.make_branch_and_tree('shared/tree')
 
237
        self.assertEqual(
 
238
            [('shared repository', srepo.bzrdir.root_transport.base),
 
239
             ('repository branch', tree.branch.base)],
 
240
            info.gather_location_info(srepo, tree.branch, tree, srepo.bzrdir))
 
241
 
 
242
    def test_gather_location_light_checkout(self):
 
243
        tree = self.make_branch_and_tree('tree')
 
244
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
 
245
        self.assertEqual(
 
246
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
 
247
             ('checkout of branch', tree.bzrdir.root_transport.base)],
 
248
            self.gather_tree_location_info(lcheckout))
 
249
 
 
250
    def test_gather_location_heavy_checkout(self):
 
251
        tree = self.make_branch_and_tree('tree')
 
252
        checkout = tree.branch.create_checkout('checkout')
 
253
        self.assertEqual(
 
254
            [('checkout root', checkout.bzrdir.root_transport.base),
 
255
             ('checkout of branch', tree.bzrdir.root_transport.base)],
 
256
            self.gather_tree_location_info(checkout))
 
257
        light_checkout = checkout.branch.create_checkout('light_checkout',
 
258
                                                         lightweight=True)
 
259
        self.assertEqual(
 
260
            [('light checkout root',
 
261
              light_checkout.bzrdir.root_transport.base),
 
262
             ('checkout root', checkout.bzrdir.root_transport.base),
 
263
             ('checkout of branch', tree.bzrdir.root_transport.base)],
 
264
             self.gather_tree_location_info(light_checkout)
 
265
             )
 
266
 
 
267
    def test_gather_location_shared_repo_checkout(self):
 
268
        tree = self.make_branch_and_tree('tree')
 
269
        srepo = self.make_repository('shared', shared=True)
 
270
        shared_checkout = tree.branch.create_checkout('shared/checkout')
 
271
        self.assertEqual(
 
272
            [('repository checkout root',
 
273
              shared_checkout.bzrdir.root_transport.base),
 
274
             ('checkout of branch', tree.bzrdir.root_transport.base),
 
275
             ('shared repository', srepo.bzrdir.root_transport.base)],
 
276
             self.gather_tree_location_info(shared_checkout))
 
277
 
 
278
    def gather_tree_location_info(self, tree):
 
279
        return info.gather_location_info(
 
280
            tree.branch.repository, tree.branch, tree, tree.bzrdir)
 
281
 
 
282
    def test_gather_location_bound(self):
 
283
        branch = self.make_branch('branch')
 
284
        bound_branch = self.make_branch('bound_branch')
 
285
        bound_branch.bind(branch)
 
286
        self.assertEqual(
 
287
            [('branch root', bound_branch.bzrdir.root_transport.base),
 
288
             ('bound to branch', branch.bzrdir.root_transport.base)],
 
289
            info.gather_location_info(
 
290
                bound_branch.repository, bound_branch, control=bound_branch.bzrdir)
 
291
        )
 
292
 
 
293
    def test_gather_location_bound_in_repository(self):
 
294
        repo = self.make_repository('repo', shared=True)
 
295
        repo.set_make_working_trees(False)
 
296
        branch = self.make_branch('branch')
 
297
        bound_branch = controldir.ControlDir.create_branch_convenience(
 
298
            'repo/bound_branch')
 
299
        bound_branch.bind(branch)
 
300
        self.assertEqual(
 
301
            [('shared repository', bound_branch.repository.bzrdir.user_url),
 
302
             ('repository branch', bound_branch.bzrdir.user_url),
 
303
             ('bound to branch', branch.bzrdir.user_url)],
 
304
            info.gather_location_info(bound_branch.repository, bound_branch)
 
305
        )
 
306
 
 
307
    def test_location_list(self):
 
308
        if sys.platform == 'win32':
 
309
            raise tests.TestSkipped('Windows-unfriendly test')
 
310
        locs = info.LocationList('/home/foo')
 
311
        locs.add_url('a', 'file:///home/foo/')
 
312
        locs.add_url('b', 'file:///home/foo/bar/')
 
313
        locs.add_url('c', 'file:///home/bar/bar')
 
314
        locs.add_url('d', 'http://example.com/example/')
 
315
        locs.add_url('e', None)
 
316
        self.assertEqual(locs.locs, [('a', '.'),
 
317
                                     ('b', 'bar'),
 
318
                                     ('c', '/home/bar/bar'),
 
319
                                     ('d', 'http://example.com/example/')])
 
320
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
 
321
                             '  d: http://example.com/example/\n',
 
322
                             ''.join(locs.get_lines()))
 
323
 
 
324
    def test_gather_related_braches(self):
 
325
        branch = self.make_branch('.')
 
326
        branch.lock_write()
 
327
        try:
 
328
            branch.set_public_branch('baz')
 
329
            branch.set_push_location('bar')
 
330
            branch.set_parent('foo')
 
331
            branch.set_submit_branch('qux')
 
332
        finally:
 
333
            branch.unlock()
 
334
        self.assertEqual(
 
335
            [('public branch', 'baz'), ('push branch', 'bar'),
 
336
             ('parent branch', 'foo'), ('submit branch', 'qux')],
 
337
            info._gather_related_branches(branch).locs)