/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: 2018-07-06 23:36:14 UTC
  • mto: (7027.3.2 python3-n)
  • mto: This revision was merged to the branch mainline in revision 7030.
  • Revision ID: jelmer@jelmer.uk-20180706233614-t4m8krag15t4z4lp
Update python3.passing.

Show diffs side-by-side

added added

removed removed

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