/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 bzrlib/tests/test_info.py

  • Committer: Aaron Bentley
  • Date: 2007-05-18 11:42:33 UTC
  • mto: This revision was merged to the branch mainline in revision 2528.
  • Revision ID: aaron.bentley@utoronto.ca-20070518114233-dhywq002d3fi9cti
Prevent repository.get_set_default_format from corrupting inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import sys
18
 
from urllib import quote
19
17
 
20
18
from bzrlib import (
21
19
    branch as _mod_branch,
53
51
            info.describe_layout(checkout.branch.repository, checkout.branch,
54
52
                                 checkout))
55
53
 
 
54
 
56
55
    def test_describe_repository_layout(self):
57
56
        repository = self.make_repository('.', shared=True)
58
57
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
77
76
                                 checkout))
78
77
 
79
78
    def assertTreeDescription(self, format):
80
 
        """Assert a tree's format description matches expectations"""
81
79
        self.make_branch_and_tree('%s_tree' % format, format=format)
82
80
        tree = workingtree.WorkingTree.open('%s_tree' % format)
83
81
        self.assertEqual(format, info.describe_format(tree.bzrdir,
84
82
            tree.branch.repository, tree.branch, tree))
85
83
 
86
84
    def assertCheckoutDescription(self, format, expected=None):
87
 
        """Assert a checkout's format description matches expectations"""
88
85
        if expected is None:
89
86
            expected = format
90
87
        branch = self.make_branch('%s_cobranch' % format, format=format)
98
95
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
99
96
            control.create_workingtree()
100
97
            tree = workingtree.WorkingTree.open('%s_co' % format)
101
 
            format_description = info.describe_format(tree.bzrdir,
102
 
                    tree.branch.repository, tree.branch, tree)
103
 
            self.assertEqual(expected, format_description,
104
 
                "checkout of format called %r was described as %r" %
105
 
                (expected, format_description))
 
98
            self.assertEqual(expected, info.describe_format(tree.bzrdir,
 
99
                tree.branch.repository, tree.branch, tree))
106
100
        finally:
107
101
            control._format.workingtree_format = old_format
108
102
 
109
103
    def assertBranchDescription(self, format, expected=None):
110
 
        """Assert branch's format description matches expectations"""
111
104
        if expected is None:
112
105
            expected = format
113
106
        self.make_branch('%s_branch' % format, format=format)
116
109
            branch.repository, branch, None))
117
110
 
118
111
    def assertRepoDescription(self, format, expected=None):
119
 
        """Assert repository's format description matches expectations"""
120
112
        if expected is None:
121
113
            expected = format
122
114
        self.make_repository('%s_repo' % format, format=format)
124
116
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
125
117
            repo, None, None))
126
118
 
127
 
    def test_describe_tree_format(self):
 
119
    def test_describe_format(self):
128
120
        for key in bzrdir.format_registry.keys():
129
 
            if key in bzrdir.format_registry.aliases():
 
121
            if key == 'default':
130
122
                continue
131
123
            self.assertTreeDescription(key)
132
124
 
133
 
    def test_describe_checkout_format(self):
134
125
        for key in bzrdir.format_registry.keys():
135
 
            if key in bzrdir.format_registry.aliases():
136
 
                # Aliases will not describe correctly in the UI because the
137
 
                # real format is found.
138
 
                continue
139
 
            # legacy: weave does not support checkouts
140
 
            if key == 'weave':
141
 
                continue
142
 
            if bzrdir.format_registry.get_info(key).experimental:
143
 
                # We don't require that experimental formats support checkouts
144
 
                # or describe correctly in the UI.
145
 
                continue
146
 
            if bzrdir.format_registry.get_info(key).hidden:
 
126
            if key in ('default', 'weave'):
147
127
                continue
148
128
            expected = None
149
 
            if key in ('pack-0.92',):
150
 
                expected = 'pack-0.92'
151
 
            elif key in ('knit', 'metaweave'):
152
 
                expected = 'knit or metaweave'
153
 
            elif key in ('1.14', '1.14-rich-root'):
154
 
                expected = '1.14 or 1.14-rich-root'
 
129
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
 
130
                expected = 'dirstate / dirstate-tags'
 
131
            if key in ('knit', 'metaweave'):
 
132
                expected = 'knit / metaweave'
155
133
            self.assertCheckoutDescription(key, expected)
156
134
 
157
 
    def test_describe_branch_format(self):
158
135
        for key in bzrdir.format_registry.keys():
159
 
            if key in bzrdir.format_registry.aliases():
160
 
                continue
161
 
            if bzrdir.format_registry.get_info(key).hidden:
 
136
            if key == 'default':
162
137
                continue
163
138
            expected = None
164
139
            if key in ('dirstate', 'knit'):
165
 
                expected = 'dirstate or knit'
166
 
            elif key in ('1.14',):
167
 
                expected = '1.14'
168
 
            elif key in ('1.14-rich-root',):
169
 
                expected = '1.14-rich-root'
 
140
                expected = 'dirstate / knit'
170
141
            self.assertBranchDescription(key, expected)
171
142
 
172
 
    def test_describe_repo_format(self):
173
143
        for key in bzrdir.format_registry.keys():
174
 
            if key in bzrdir.format_registry.aliases():
175
 
                continue
176
 
            if bzrdir.format_registry.get_info(key).hidden:
 
144
            if key == 'default':
177
145
                continue
178
146
            expected = None
179
147
            if key in ('dirstate', 'knit', 'dirstate-tags'):
180
 
                expected = 'dirstate or dirstate-tags or knit'
181
 
            elif key in ('1.14',):
182
 
                expected = '1.14'
183
 
            elif key in ('1.14-rich-root',):
184
 
                expected = '1.14-rich-root'
 
148
                expected = 'dirstate / dirstate-tags / knit'
185
149
            self.assertRepoDescription(key, expected)
186
150
 
187
151
        format = bzrdir.format_registry.make_bzrdir('metaweave')
189
153
        tree = self.make_branch_and_tree('unknown', format=format)
190
154
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
191
155
            tree.branch.repository, tree.branch, tree))
192
 
 
193
 
    def test_gather_location_standalone(self):
194
 
        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))
200
 
        return tree
201
 
 
202
 
    def test_gather_location_repo(self):
203
 
        srepo = self.make_repository('shared', shared=True)
204
 
        self.assertEqual([('shared repository',
205
 
                          srepo.bzrdir.root_transport.base)],
206
 
                          info.gather_location_info(srepo))
207
 
        urepo = self.make_repository('unshared')
208
 
        self.assertEqual([('repository',
209
 
                          urepo.bzrdir.root_transport.base)],
210
 
                          info.gather_location_info(urepo))
211
 
 
212
 
    def test_gather_location_repo_branch(self):
213
 
        srepo = self.make_repository('shared', shared=True)
214
 
        self.assertEqual([('shared repository',
215
 
                          srepo.bzrdir.root_transport.base)],
216
 
                          info.gather_location_info(srepo))
217
 
        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))
222
 
 
223
 
    def test_gather_location_light_checkout(self):
224
 
        tree = self.make_branch_and_tree('tree')
225
 
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
226
 
        self.assertEqual(
227
 
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
228
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
229
 
            self.gather_tree_location_info(lcheckout))
230
 
 
231
 
    def test_gather_location_heavy_checkout(self):
232
 
        tree = self.make_branch_and_tree('tree')
233
 
        checkout = tree.branch.create_checkout('checkout')
234
 
        self.assertEqual(
235
 
            [('checkout root', checkout.bzrdir.root_transport.base),
236
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
237
 
            self.gather_tree_location_info(checkout))
238
 
        light_checkout = checkout.branch.create_checkout('light_checkout',
239
 
                                                         lightweight=True)
240
 
        self.assertEqual(
241
 
            [('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)],
245
 
             self.gather_tree_location_info(light_checkout)
246
 
             )
247
 
 
248
 
    def test_gather_location_shared_repo_checkout(self):
249
 
        tree = self.make_branch_and_tree('tree')
250
 
        srepo = self.make_repository('shared', shared=True)
251
 
        shared_checkout = tree.branch.create_checkout('shared/checkout')
252
 
        self.assertEqual(
253
 
            [('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)],
257
 
             self.gather_tree_location_info(shared_checkout))
258
 
 
259
 
    def gather_tree_location_info(self, tree):
260
 
        return info.gather_location_info(tree.branch.repository, tree.branch,
261
 
                                         tree)
262
 
 
263
 
    def test_gather_location_bound(self):
264
 
        branch = self.make_branch('branch')
265
 
        bound_branch = self.make_branch('bound_branch')
266
 
        bound_branch.bind(branch)
267
 
        self.assertEqual(
268
 
            [('branch root', bound_branch.bzrdir.root_transport.base),
269
 
             ('bound to branch', branch.bzrdir.root_transport.base)],
270
 
            info.gather_location_info(bound_branch.repository, bound_branch)
271
 
        )
272
 
 
273
 
    def test_location_list(self):
274
 
        if sys.platform == 'win32':
275
 
            raise tests.TestSkipped('Windows-unfriendly test')
276
 
        locs = info.LocationList('/home/foo')
277
 
        locs.add_url('a', 'file:///home/foo/')
278
 
        locs.add_url('b', 'file:///home/foo/bar/')
279
 
        locs.add_url('c', 'file:///home/bar/bar')
280
 
        locs.add_url('d', 'http://example.com/example/')
281
 
        locs.add_url('e', None)
282
 
        self.assertEqual(locs.locs, [('a', '.'),
283
 
                                     ('b', 'bar'),
284
 
                                     ('c', '/home/bar/bar'),
285
 
                                     ('d', 'http://example.com/example/')])
286
 
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
287
 
                             '  d: http://example.com/example/\n',
288
 
                             ''.join(locs.get_lines()))
289
 
 
290
 
    def test_gather_related_braches(self):
291
 
        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')
296
 
        self.assertEqual(
297
 
            [('public branch', 'baz'), ('push branch', 'bar'),
298
 
             ('parent branch', 'foo'), ('submit branch', 'qux')],
299
 
            info._gather_related_branches(branch).locs)