/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-10 21:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610215915-zcpu0in3r1irx3ml
Move serializer to bzr.

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