/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 01:35:53 UTC
  • mto: (6670.4.8 move-bzr)
  • mto: This revision was merged to the branch mainline in revision 6681.
  • Revision ID: jelmer@jelmer.uk-20170610013553-560y7mn3su4pp763
Fix remaining tests.

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