~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-22 10:53:21 UTC
  • mto: This revision was merged to the branch mainline in revision 6094.
  • Revision ID: jelmer@samba.org-20110822105321-bxzxabfs6pl7lc43
Remove tags pointed at by uncommitted revisions.

Show diffs side-by-side

added added

removed removed

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