~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: 2014-10-06 16:32:42 UTC
  • mfrom: (6597.2.4 split-diff-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20141006163242-c2cll01cwc24grkk
(vila) Split some tests to be able to get finer grained failures (Vincent
 Ladeuil)

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
 
from urllib import quote
 
17
import sys
18
18
 
19
19
from bzrlib import (
20
20
    branch as _mod_branch,
21
 
    bzrdir,
 
21
    controldir,
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('Unshared repository with trees',
35
 
            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))
36
37
        tree.branch.repository.set_make_working_trees(False)
37
 
        self.assertEqual('Unshared repository',
38
 
            info.describe_layout(tree.branch.repository))
 
38
        self.assertEqual('Unshared repository with colocated branches',
 
39
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
39
40
        self.assertEqual('Standalone branch',
40
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
41
            info.describe_layout(tree.branch.repository, tree.branch,
 
42
                control=tree.bzrdir))
41
43
        self.assertEqual('Standalone branchless tree',
42
 
            info.describe_layout(tree.branch.repository, None, tree))
 
44
            info.describe_layout(tree.branch.repository, None, tree,
 
45
                control=tree.bzrdir))
43
46
        self.assertEqual('Standalone tree',
44
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
47
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
48
                control=tree.bzrdir))
45
49
        tree.branch.bind(tree.branch)
46
50
        self.assertEqual('Bound branch',
47
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
51
            info.describe_layout(tree.branch.repository, tree.branch,
 
52
                control=tree.bzrdir))
48
53
        self.assertEqual('Checkout',
49
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
54
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
55
                control=tree.bzrdir))
50
56
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
51
57
        self.assertEqual('Lightweight checkout',
52
58
            info.describe_layout(checkout.branch.repository, checkout.branch,
53
 
                                 checkout))
 
59
                                 checkout, control=tree.bzrdir))
54
60
 
55
61
    def test_describe_repository_layout(self):
56
62
        repository = self.make_repository('.', shared=True)
57
 
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
 
63
        tree = controldir.ControlDir.create_branch_convenience('tree',
58
64
            force_new_tree=True).bzrdir.open_workingtree()
59
 
        self.assertEqual('Shared repository with trees',
60
 
            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))
61
67
        repository.set_make_working_trees(False)
62
 
        self.assertEqual('Shared repository',
63
 
            info.describe_layout(tree.branch.repository))
 
68
        self.assertEqual('Shared repository with colocated branches',
 
69
            info.describe_layout(tree.branch.repository, control=tree.bzrdir))
64
70
        self.assertEqual('Repository branch',
65
 
            info.describe_layout(tree.branch.repository, tree.branch))
 
71
            info.describe_layout(tree.branch.repository, tree.branch,
 
72
                control=tree.bzrdir))
66
73
        self.assertEqual('Repository branchless tree',
67
 
            info.describe_layout(tree.branch.repository, None, tree))
 
74
            info.describe_layout(tree.branch.repository, None, tree,
 
75
                control=tree.bzrdir))
68
76
        self.assertEqual('Repository tree',
69
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
77
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
78
                control=tree.bzrdir))
70
79
        tree.branch.bind(tree.branch)
71
80
        self.assertEqual('Repository checkout',
72
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
81
            info.describe_layout(tree.branch.repository, tree.branch, tree,
 
82
                control=tree.bzrdir))
73
83
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
74
84
        self.assertEqual('Lightweight checkout',
75
85
            info.describe_layout(checkout.branch.repository, checkout.branch,
76
 
                                 checkout))
 
86
                                 checkout, control=tree.bzrdir))
77
87
 
78
88
    def assertTreeDescription(self, format):
79
89
        """Assert a tree's format description matches expectations"""
90
100
        # this ought to be easier...
91
101
        branch.create_checkout('%s_co' % format,
92
102
            lightweight=True).bzrdir.destroy_workingtree()
93
 
        control = bzrdir.BzrDir.open('%s_co' % format)
 
103
        control = controldir.ControlDir.open('%s_co' % format)
94
104
        old_format = control._format.workingtree_format
95
105
        try:
96
106
            control._format.workingtree_format = \
97
 
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
 
107
                controldir.format_registry.make_bzrdir(format).workingtree_format
98
108
            control.create_workingtree()
99
109
            tree = workingtree.WorkingTree.open('%s_co' % format)
100
 
            self.assertEqual(expected, info.describe_format(tree.bzrdir,
101
 
                tree.branch.repository, tree.branch, tree))
 
110
            format_description = info.describe_format(tree.bzrdir,
 
111
                    tree.branch.repository, tree.branch, tree)
 
112
            self.assertEqual(expected, format_description,
 
113
                "checkout of format called %r was described as %r" %
 
114
                (expected, format_description))
102
115
        finally:
103
116
            control._format.workingtree_format = old_format
104
117
 
121
134
            repo, None, None))
122
135
 
123
136
    def test_describe_tree_format(self):
124
 
        for key in bzrdir.format_registry.keys():
125
 
            if key == 'default':
 
137
        for key in controldir.format_registry.keys():
 
138
            if key in controldir.format_registry.aliases():
126
139
                continue
127
140
            self.assertTreeDescription(key)
128
141
 
129
142
    def test_describe_checkout_format(self):
130
 
        for key in bzrdir.format_registry.keys():
131
 
            if key in ('default', 'weave'):
 
143
        for key in controldir.format_registry.keys():
 
144
            if key in controldir.format_registry.aliases():
 
145
                # Aliases will not describe correctly in the UI because the
 
146
                # real format is found.
 
147
                continue
 
148
            # legacy: weave does not support checkouts
 
149
            if key == 'weave':
 
150
                continue
 
151
            if controldir.format_registry.get_info(key).experimental:
 
152
                # We don't require that experimental formats support checkouts
 
153
                # or describe correctly in the UI.
 
154
                continue
 
155
            if controldir.format_registry.get_info(key).hidden:
132
156
                continue
133
157
            expected = None
134
 
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
135
 
                expected = 'dirstate or dirstate-tags'
136
 
            if key in ('knit', 'metaweave'):
137
 
                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'
138
167
            self.assertCheckoutDescription(key, expected)
139
168
 
140
169
    def test_describe_branch_format(self):
141
 
        for key in bzrdir.format_registry.keys():
142
 
            if key == 'default':
 
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:
143
174
                continue
144
175
            expected = None
145
176
            if key in ('dirstate', 'knit'):
146
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'
147
182
            self.assertBranchDescription(key, expected)
148
183
 
149
184
    def test_describe_repo_format(self):
150
 
        for key in bzrdir.format_registry.keys():
151
 
            if key == 'default':
 
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:
152
189
                continue
153
190
            expected = None
154
191
            if key in ('dirstate', 'knit', 'dirstate-tags'):
155
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'
156
197
            self.assertRepoDescription(key, expected)
157
198
 
158
 
        format = bzrdir.format_registry.make_bzrdir('metaweave')
 
199
        format = controldir.format_registry.make_bzrdir('knit')
159
200
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
160
201
        tree = self.make_branch_and_tree('unknown', format=format)
161
202
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
162
203
            tree.branch.repository, tree.branch, tree))
163
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
 
164
210
    def test_gather_location_standalone(self):
165
211
        tree = self.make_branch_and_tree('tree')
166
212
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
167
 
            info.gather_location_info(tree.branch.repository, tree.branch,
168
 
                                      tree))
 
213
            info.gather_location_info(
 
214
                tree.branch.repository, tree.branch, tree, control=tree.bzrdir))
169
215
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
170
 
            info.gather_location_info(tree.branch.repository, tree.branch))
 
216
            info.gather_location_info(
 
217
                tree.branch.repository, tree.branch, control=tree.bzrdir))
171
218
        return tree
172
219
 
173
220
    def test_gather_location_repo(self):
174
221
        srepo = self.make_repository('shared', shared=True)
175
 
        self.assertEqual([('shared repository',
176
 
                          srepo.bzrdir.root_transport.base)],
177
 
                          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))
178
225
        urepo = self.make_repository('unshared')
179
 
        self.assertEqual([('repository',
180
 
                          urepo.bzrdir.root_transport.base)],
181
 
                          info.gather_location_info(urepo))
 
226
        self.assertEqual(
 
227
            [('repository', urepo.bzrdir.root_transport.base)],
 
228
            info.gather_location_info(urepo, control=urepo.bzrdir))
182
229
 
183
230
    def test_gather_location_repo_branch(self):
184
231
        srepo = self.make_repository('shared', shared=True)
185
 
        self.assertEqual([('shared repository',
186
 
                          srepo.bzrdir.root_transport.base)],
187
 
                          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))
188
235
        tree = self.make_branch_and_tree('shared/tree')
189
 
        self.assertEqual([('shared repository',
190
 
                          srepo.bzrdir.root_transport.base),
191
 
                          ('repository branch', tree.branch.base)],
192
 
                          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))
193
240
 
194
241
    def test_gather_location_light_checkout(self):
195
242
        tree = self.make_branch_and_tree('tree')
228
275
             self.gather_tree_location_info(shared_checkout))
229
276
 
230
277
    def gather_tree_location_info(self, tree):
231
 
        return info.gather_location_info(tree.branch.repository, tree.branch,
232
 
                                         tree)
 
278
        return info.gather_location_info(
 
279
            tree.branch.repository, tree.branch, tree, tree.bzrdir)
233
280
 
234
281
    def test_gather_location_bound(self):
235
282
        branch = self.make_branch('branch')
238
285
        self.assertEqual(
239
286
            [('branch root', bound_branch.bzrdir.root_transport.base),
240
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)],
241
303
            info.gather_location_info(bound_branch.repository, bound_branch)
242
304
        )
243
305
 
244
306
    def test_location_list(self):
 
307
        if sys.platform == 'win32':
 
308
            raise tests.TestSkipped('Windows-unfriendly test')
245
309
        locs = info.LocationList('/home/foo')
246
310
        locs.add_url('a', 'file:///home/foo/')
247
311
        locs.add_url('b', 'file:///home/foo/bar/')
258
322
 
259
323
    def test_gather_related_braches(self):
260
324
        branch = self.make_branch('.')
261
 
        branch.set_public_branch('baz')
262
 
        branch.set_push_location('bar')
263
 
        branch.set_parent('foo')
264
 
        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()
265
333
        self.assertEqual(
266
334
            [('public branch', 'baz'), ('push branch', 'bar'),
267
335
             ('parent branch', 'foo'), ('submit branch', 'qux')],