~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

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