~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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
19
from bzrlib import (
21
20
    branch as _mod_branch,
22
 
    bzrdir,
 
21
    controldir,
23
22
    info,
24
23
    tests,
25
24
    workingtree,
32
31
    def test_describe_standalone_layout(self):
33
32
        tree = self.make_branch_and_tree('tree')
34
33
        self.assertEqual('Empty control directory', info.describe_layout())
35
 
        self.assertEqual('Unshared repository with trees',
36
 
            info.describe_layout(tree.branch.repository))
 
34
        self.assertEqual(
 
35
            'Unshared repository with trees and colocated branches',
 
36
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
37
37
        tree.branch.repository.set_make_working_trees(False)
38
 
        self.assertEqual('Unshared repository',
39
 
            info.describe_layout(tree.branch.repository))
 
38
        self.assertEqual('Unshared repository with colocated branches',
 
39
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
40
40
        self.assertEqual('Standalone branch',
41
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
41
            info.describe_layout(tree.branch.repository, tree.branch,
 
42
                control=tree.bzrdir))
42
43
        self.assertEqual('Standalone branchless tree',
43
 
            info.describe_layout(tree.branch.repository, None, tree))
 
44
            info.describe_layout(tree.branch.repository, None, tree,
 
45
                control=tree.bzrdir))
44
46
        self.assertEqual('Standalone tree',
45
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
47
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
48
                control=tree.bzrdir))
46
49
        tree.branch.bind(tree.branch)
47
50
        self.assertEqual('Bound branch',
48
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
51
            info.describe_layout(tree.branch.repository, tree.branch,
 
52
                control=tree.bzrdir))
49
53
        self.assertEqual('Checkout',
50
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
54
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
55
                control=tree.bzrdir))
51
56
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
52
57
        self.assertEqual('Lightweight checkout',
53
58
            info.describe_layout(checkout.branch.repository, checkout.branch,
54
 
                                 checkout))
 
59
                                 checkout, control=tree.bzrdir))
55
60
 
56
61
    def test_describe_repository_layout(self):
57
62
        repository = self.make_repository('.', shared=True)
58
 
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
 
63
        tree = controldir.ControlDir.create_branch_convenience('tree',
59
64
            force_new_tree=True).bzrdir.open_workingtree()
60
 
        self.assertEqual('Shared repository with trees',
61
 
            info.describe_layout(tree.branch.repository))
 
65
        self.assertEqual('Shared repository with trees and colocated branches',
 
66
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
62
67
        repository.set_make_working_trees(False)
63
 
        self.assertEqual('Shared repository',
64
 
            info.describe_layout(tree.branch.repository))
 
68
        self.assertEqual('Shared repository with colocated branches',
 
69
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
65
70
        self.assertEqual('Repository branch',
66
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
71
            info.describe_layout(tree.branch.repository, tree.branch,
 
72
                control=tree.bzrdir))
67
73
        self.assertEqual('Repository branchless tree',
68
 
            info.describe_layout(tree.branch.repository, None, tree))
 
74
            info.describe_layout(tree.branch.repository, None, tree,
 
75
                control=tree.bzrdir))
69
76
        self.assertEqual('Repository tree',
70
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
77
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
78
                control=tree.bzrdir))
71
79
        tree.branch.bind(tree.branch)
72
80
        self.assertEqual('Repository checkout',
73
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
81
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
82
                control=tree.bzrdir))
74
83
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
75
84
        self.assertEqual('Lightweight checkout',
76
85
            info.describe_layout(checkout.branch.repository, checkout.branch,
77
 
                                 checkout))
 
86
                                 checkout, control=tree.bzrdir))
78
87
 
79
88
    def assertTreeDescription(self, format):
80
89
        """Assert a tree's format description matches expectations"""
91
100
        # this ought to be easier...
92
101
        branch.create_checkout('%s_co' % format,
93
102
            lightweight=True).bzrdir.destroy_workingtree()
94
 
        control = bzrdir.BzrDir.open('%s_co' % format)
 
103
        control = controldir.ControlDir.open('%s_co' % format)
95
104
        old_format = control._format.workingtree_format
96
105
        try:
97
106
            control._format.workingtree_format = \
98
 
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
 
107
                controldir.format_registry.make_bzrdir(format).workingtree_format
99
108
            control.create_workingtree()
100
109
            tree = workingtree.WorkingTree.open('%s_co' % format)
101
110
            format_description = info.describe_format(tree.bzrdir,
125
134
            repo, None, None))
126
135
 
127
136
    def test_describe_tree_format(self):
128
 
        for key in bzrdir.format_registry.keys():
129
 
            if key in bzrdir.format_registry.aliases():
 
137
        for key in controldir.format_registry.keys():
 
138
            if key in controldir.format_registry.aliases():
130
139
                continue
131
140
            self.assertTreeDescription(key)
132
141
 
133
142
    def test_describe_checkout_format(self):
134
 
        for key in bzrdir.format_registry.keys():
135
 
            if key in bzrdir.format_registry.aliases():
 
143
        for key in controldir.format_registry.keys():
 
144
            if key in controldir.format_registry.aliases():
136
145
                # Aliases will not describe correctly in the UI because the
137
146
                # real format is found.
138
147
                continue
139
148
            # legacy: weave does not support checkouts
140
149
            if key == 'weave':
141
150
                continue
142
 
            if bzrdir.format_registry.get_info(key).experimental:
 
151
            if controldir.format_registry.get_info(key).experimental:
143
152
                # We don't require that experimental formats support checkouts
144
153
                # or describe correctly in the UI.
145
154
                continue
 
155
            if controldir.format_registry.get_info(key).hidden:
 
156
                continue
146
157
            expected = None
147
 
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
148
 
                'pack-0.92', 'pack-0.92-subtree', 'rich-root',
149
 
                'rich-root-pack', '1.6', '1.6.1-rich-root'):
150
 
                expected = '1.6 or 1.6.1-rich-root or ' \
151
 
                    'dirstate or dirstate-tags or pack-0.92 or'\
152
 
                    ' rich-root or rich-root-pack'
153
 
            if key in ('knit', 'metaweave'):
154
 
                expected = 'knit or metaweave'
 
158
            if key in ('pack-0.92',):
 
159
                expected = 'pack-0.92'
 
160
            elif key in ('knit', 'metaweave'):
 
161
                if 'metaweave' in controldir.format_registry:
 
162
                    expected = 'knit or metaweave'
 
163
                else:
 
164
                    expected = 'knit'
 
165
            elif key in ('1.14', '1.14-rich-root'):
 
166
                expected = '1.14 or 1.14-rich-root'
155
167
            self.assertCheckoutDescription(key, expected)
156
168
 
157
169
    def test_describe_branch_format(self):
158
 
        for key in bzrdir.format_registry.keys():
159
 
            if key in bzrdir.format_registry.aliases():
 
170
        for key in controldir.format_registry.keys():
 
171
            if key in controldir.format_registry.aliases():
 
172
                continue
 
173
            if controldir.format_registry.get_info(key).hidden:
160
174
                continue
161
175
            expected = None
162
176
            if key in ('dirstate', 'knit'):
163
177
                expected = 'dirstate or knit'
 
178
            elif key in ('1.14',):
 
179
                expected = '1.14'
 
180
            elif key in ('1.14-rich-root',):
 
181
                expected = '1.14-rich-root'
164
182
            self.assertBranchDescription(key, expected)
165
183
 
166
184
    def test_describe_repo_format(self):
167
 
        for key in bzrdir.format_registry.keys():
168
 
            if key in bzrdir.format_registry.aliases():
 
185
        for key in controldir.format_registry.keys():
 
186
            if key in controldir.format_registry.aliases():
 
187
                continue
 
188
            if controldir.format_registry.get_info(key).hidden:
169
189
                continue
170
190
            expected = None
171
191
            if key in ('dirstate', 'knit', 'dirstate-tags'):
172
192
                expected = 'dirstate or dirstate-tags or knit'
 
193
            elif key in ('1.14',):
 
194
                expected = '1.14'
 
195
            elif key in ('1.14-rich-root',):
 
196
                expected = '1.14-rich-root'
173
197
            self.assertRepoDescription(key, expected)
174
198
 
175
 
        format = bzrdir.format_registry.make_bzrdir('metaweave')
 
199
        format = controldir.format_registry.make_bzrdir('knit')
176
200
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
177
201
        tree = self.make_branch_and_tree('unknown', format=format)
178
202
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
179
203
            tree.branch.repository, tree.branch, tree))
180
204
 
 
205
    def test_gather_location_controldir_only(self):
 
206
        bzrdir = self.make_bzrdir('.')
 
207
        self.assertEqual([('control directory', bzrdir.user_url)],
 
208
            info.gather_location_info(control=bzrdir))
 
209
 
181
210
    def test_gather_location_standalone(self):
182
211
        tree = self.make_branch_and_tree('tree')
183
212
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
184
 
            info.gather_location_info(tree.branch.repository, tree.branch,
185
 
                                      tree))
 
213
            info.gather_location_info(
 
214
                tree.branch.repository, tree.branch, tree, control=tree.bzrdir))
186
215
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
187
 
            info.gather_location_info(tree.branch.repository, tree.branch))
 
216
            info.gather_location_info(
 
217
                tree.branch.repository, tree.branch, control=tree.bzrdir))
188
218
        return tree
189
219
 
190
220
    def test_gather_location_repo(self):
191
221
        srepo = self.make_repository('shared', shared=True)
192
 
        self.assertEqual([('shared repository',
193
 
                          srepo.bzrdir.root_transport.base)],
194
 
                          info.gather_location_info(srepo))
 
222
        self.assertEqual(
 
223
            [('shared repository', srepo.bzrdir.root_transport.base)],
 
224
            info.gather_location_info(srepo, control=srepo.bzrdir))
195
225
        urepo = self.make_repository('unshared')
196
 
        self.assertEqual([('repository',
197
 
                          urepo.bzrdir.root_transport.base)],
198
 
                          info.gather_location_info(urepo))
 
226
        self.assertEqual(
 
227
            [('repository', urepo.bzrdir.root_transport.base)],
 
228
            info.gather_location_info(urepo, control=urepo.bzrdir))
199
229
 
200
230
    def test_gather_location_repo_branch(self):
201
231
        srepo = self.make_repository('shared', shared=True)
202
 
        self.assertEqual([('shared repository',
203
 
                          srepo.bzrdir.root_transport.base)],
204
 
                          info.gather_location_info(srepo))
 
232
        self.assertEqual(
 
233
            [('shared repository', srepo.bzrdir.root_transport.base)],
 
234
            info.gather_location_info(srepo, control=srepo.bzrdir))
205
235
        tree = self.make_branch_and_tree('shared/tree')
206
 
        self.assertEqual([('shared repository',
207
 
                          srepo.bzrdir.root_transport.base),
208
 
                          ('repository branch', tree.branch.base)],
209
 
                          info.gather_location_info(srepo, tree.branch, tree))
 
236
        self.assertEqual(
 
237
            [('shared repository', srepo.bzrdir.root_transport.base),
 
238
             ('repository branch', tree.branch.base)],
 
239
            info.gather_location_info(srepo, tree.branch, tree, srepo.bzrdir))
210
240
 
211
241
    def test_gather_location_light_checkout(self):
212
242
        tree = self.make_branch_and_tree('tree')
245
275
             self.gather_tree_location_info(shared_checkout))
246
276
 
247
277
    def gather_tree_location_info(self, tree):
248
 
        return info.gather_location_info(tree.branch.repository, tree.branch,
249
 
                                         tree)
 
278
        return info.gather_location_info(
 
279
            tree.branch.repository, tree.branch, tree, tree.bzrdir)
250
280
 
251
281
    def test_gather_location_bound(self):
252
282
        branch = self.make_branch('branch')
255
285
        self.assertEqual(
256
286
            [('branch root', bound_branch.bzrdir.root_transport.base),
257
287
             ('bound to branch', branch.bzrdir.root_transport.base)],
 
288
            info.gather_location_info(
 
289
                bound_branch.repository, bound_branch, control=bound_branch.bzrdir)
 
290
        )
 
291
 
 
292
    def test_gather_location_bound_in_repository(self):
 
293
        repo = self.make_repository('repo', shared=True)
 
294
        repo.set_make_working_trees(False)
 
295
        branch = self.make_branch('branch')
 
296
        bound_branch = controldir.ControlDir.create_branch_convenience(
 
297
            'repo/bound_branch')
 
298
        bound_branch.bind(branch)
 
299
        self.assertEqual(
 
300
            [('shared repository', bound_branch.repository.bzrdir.user_url),
 
301
             ('repository branch', bound_branch.bzrdir.user_url),
 
302
             ('bound to branch', branch.bzrdir.user_url)],
258
303
            info.gather_location_info(bound_branch.repository, bound_branch)
259
304
        )
260
305
 
277
322
 
278
323
    def test_gather_related_braches(self):
279
324
        branch = self.make_branch('.')
280
 
        branch.set_public_branch('baz')
281
 
        branch.set_push_location('bar')
282
 
        branch.set_parent('foo')
283
 
        branch.set_submit_branch('qux')
 
325
        branch.lock_write()
 
326
        try:
 
327
            branch.set_public_branch('baz')
 
328
            branch.set_push_location('bar')
 
329
            branch.set_parent('foo')
 
330
            branch.set_submit_branch('qux')
 
331
        finally:
 
332
            branch.unlock()
284
333
        self.assertEqual(
285
334
            [('public branch', 'baz'), ('push branch', 'bar'),
286
335
             ('parent branch', 'foo'), ('submit branch', 'qux')],