~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-09-04 02:59:56 UTC
  • mfrom: (1172)
  • mto: (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: aaron.bentley@utoronto.ca-20050904025956-776ba4f07de97700
Merged mpool's latest changes (~0.0.7)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
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
16
 
 
17
 
from urllib import quote
18
 
 
19
 
from bzrlib import (
20
 
    branch as _mod_branch,
21
 
    bzrdir,
22
 
    info,
23
 
    tests,
24
 
    workingtree,
25
 
    repository as _mod_repository,
26
 
    )
27
 
 
28
 
 
29
 
class TestInfo(tests.TestCaseWithTransport):
30
 
 
31
 
    def test_describe_standalone_layout(self):
32
 
        tree = self.make_branch_and_tree('tree')
33
 
        self.assertEqual('Empty control directory', info.describe_layout())
34
 
        self.assertEqual('Unshared repository with trees',
35
 
            info.describe_layout(tree.branch.repository))
36
 
        tree.branch.repository.set_make_working_trees(False)
37
 
        self.assertEqual('Unshared repository',
38
 
            info.describe_layout(tree.branch.repository))
39
 
        self.assertEqual('Standalone branch',
40
 
            info.describe_layout(tree.branch.repository, tree.branch))
41
 
        self.assertEqual('Standalone branchless tree',
42
 
            info.describe_layout(tree.branch.repository, None, tree))
43
 
        self.assertEqual('Standalone tree',
44
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
45
 
        tree.branch.bind(tree.branch)
46
 
        self.assertEqual('Bound branch',
47
 
            info.describe_layout(tree.branch.repository, tree.branch))
48
 
        self.assertEqual('Checkout',
49
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
50
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
51
 
        self.assertEqual('Lightweight checkout',
52
 
            info.describe_layout(checkout.branch.repository, checkout.branch,
53
 
                                 checkout))
54
 
 
55
 
    def test_describe_repository_layout(self):
56
 
        repository = self.make_repository('.', shared=True)
57
 
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
58
 
            force_new_tree=True).bzrdir.open_workingtree()
59
 
        self.assertEqual('Shared repository with trees',
60
 
            info.describe_layout(tree.branch.repository))
61
 
        repository.set_make_working_trees(False)
62
 
        self.assertEqual('Shared repository',
63
 
            info.describe_layout(tree.branch.repository))
64
 
        self.assertEqual('Repository branch',
65
 
            info.describe_layout(tree.branch.repository, tree.branch))
66
 
        self.assertEqual('Repository branchless tree',
67
 
            info.describe_layout(tree.branch.repository, None, tree))
68
 
        self.assertEqual('Repository tree',
69
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
70
 
        tree.branch.bind(tree.branch)
71
 
        self.assertEqual('Repository checkout',
72
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
73
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
74
 
        self.assertEqual('Lightweight checkout',
75
 
            info.describe_layout(checkout.branch.repository, checkout.branch,
76
 
                                 checkout))
77
 
 
78
 
    def assertTreeDescription(self, format):
79
 
        """Assert a tree's format description matches expectations"""
80
 
        self.make_branch_and_tree('%s_tree' % format, format=format)
81
 
        tree = workingtree.WorkingTree.open('%s_tree' % format)
82
 
        self.assertEqual(format, info.describe_format(tree.bzrdir,
83
 
            tree.branch.repository, tree.branch, tree))
84
 
 
85
 
    def assertCheckoutDescription(self, format, expected=None):
86
 
        """Assert a checkout's format description matches expectations"""
87
 
        if expected is None:
88
 
            expected = format
89
 
        branch = self.make_branch('%s_cobranch' % format, format=format)
90
 
        # this ought to be easier...
91
 
        branch.create_checkout('%s_co' % format,
92
 
            lightweight=True).bzrdir.destroy_workingtree()
93
 
        control = bzrdir.BzrDir.open('%s_co' % format)
94
 
        old_format = control._format.workingtree_format
95
 
        try:
96
 
            control._format.workingtree_format = \
97
 
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
98
 
            control.create_workingtree()
99
 
            tree = workingtree.WorkingTree.open('%s_co' % format)
100
 
            format_description = info.describe_format(tree.bzrdir,
101
 
                    tree.branch.repository, tree.branch, tree)
102
 
            self.assertEqual(expected, format_description,
103
 
                "checkout of format called %r was described as %r" %
104
 
                (expected, format_description))
105
 
        finally:
106
 
            control._format.workingtree_format = old_format
107
 
 
108
 
    def assertBranchDescription(self, format, expected=None):
109
 
        """Assert branch's format description matches expectations"""
110
 
        if expected is None:
111
 
            expected = format
112
 
        self.make_branch('%s_branch' % format, format=format)
113
 
        branch = _mod_branch.Branch.open('%s_branch' % format)
114
 
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
115
 
            branch.repository, branch, None))
116
 
 
117
 
    def assertRepoDescription(self, format, expected=None):
118
 
        """Assert repository's format description matches expectations"""
119
 
        if expected is None:
120
 
            expected = format
121
 
        self.make_repository('%s_repo' % format, format=format)
122
 
        repo = _mod_repository.Repository.open('%s_repo' % format)
123
 
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
124
 
            repo, None, None))
125
 
 
126
 
    def test_describe_tree_format(self):
127
 
        for key in bzrdir.format_registry.keys():
128
 
            if key == 'default':
129
 
                continue
130
 
            self.assertTreeDescription(key)
131
 
 
132
 
    def test_describe_checkout_format(self):
133
 
        for key in bzrdir.format_registry.keys():
134
 
            if key in ('default', 'weave', 'experimental'):
135
 
                continue
136
 
            if key.startswith('experimental-'):
137
 
                # these are typically hidden or aliases for other formats
138
 
                continue
139
 
            expected = None
140
 
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
141
 
                expected = 'dirstate or dirstate-tags'
142
 
            if key in ('knit', 'metaweave'):
143
 
                expected = 'knit or metaweave'
144
 
            self.assertCheckoutDescription(key, expected)
145
 
 
146
 
    def test_describe_branch_format(self):
147
 
        for key in bzrdir.format_registry.keys():
148
 
            if key == 'default':
149
 
                continue
150
 
            expected = None
151
 
            if key in ('dirstate', 'knit'):
152
 
                expected = 'dirstate or knit'
153
 
            self.assertBranchDescription(key, expected)
154
 
 
155
 
    def test_describe_repo_format(self):
156
 
        for key in bzrdir.format_registry.keys():
157
 
            if key == 'default':
158
 
                continue
159
 
            expected = None
160
 
            if key in ('dirstate', 'knit', 'dirstate-tags'):
161
 
                expected = 'dirstate or dirstate-tags or knit'
162
 
            self.assertRepoDescription(key, expected)
163
 
 
164
 
        format = bzrdir.format_registry.make_bzrdir('metaweave')
165
 
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
166
 
        tree = self.make_branch_and_tree('unknown', format=format)
167
 
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
168
 
            tree.branch.repository, tree.branch, tree))
169
 
 
170
 
    def test_gather_location_standalone(self):
171
 
        tree = self.make_branch_and_tree('tree')
172
 
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
173
 
            info.gather_location_info(tree.branch.repository, tree.branch,
174
 
                                      tree))
175
 
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
176
 
            info.gather_location_info(tree.branch.repository, tree.branch))
177
 
        return tree
178
 
 
179
 
    def test_gather_location_repo(self):
180
 
        srepo = self.make_repository('shared', shared=True)
181
 
        self.assertEqual([('shared repository',
182
 
                          srepo.bzrdir.root_transport.base)],
183
 
                          info.gather_location_info(srepo))
184
 
        urepo = self.make_repository('unshared')
185
 
        self.assertEqual([('repository',
186
 
                          urepo.bzrdir.root_transport.base)],
187
 
                          info.gather_location_info(urepo))
188
 
 
189
 
    def test_gather_location_repo_branch(self):
190
 
        srepo = self.make_repository('shared', shared=True)
191
 
        self.assertEqual([('shared repository',
192
 
                          srepo.bzrdir.root_transport.base)],
193
 
                          info.gather_location_info(srepo))
194
 
        tree = self.make_branch_and_tree('shared/tree')
195
 
        self.assertEqual([('shared repository',
196
 
                          srepo.bzrdir.root_transport.base),
197
 
                          ('repository branch', tree.branch.base)],
198
 
                          info.gather_location_info(srepo, tree.branch, tree))
199
 
 
200
 
    def test_gather_location_light_checkout(self):
201
 
        tree = self.make_branch_and_tree('tree')
202
 
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
203
 
        self.assertEqual(
204
 
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
205
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
206
 
            self.gather_tree_location_info(lcheckout))
207
 
 
208
 
    def test_gather_location_heavy_checkout(self):
209
 
        tree = self.make_branch_and_tree('tree')
210
 
        checkout = tree.branch.create_checkout('checkout')
211
 
        self.assertEqual(
212
 
            [('checkout root', checkout.bzrdir.root_transport.base),
213
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
214
 
            self.gather_tree_location_info(checkout))
215
 
        light_checkout = checkout.branch.create_checkout('light_checkout',
216
 
                                                         lightweight=True)
217
 
        self.assertEqual(
218
 
            [('light checkout root',
219
 
              light_checkout.bzrdir.root_transport.base),
220
 
             ('checkout root', checkout.bzrdir.root_transport.base),
221
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
222
 
             self.gather_tree_location_info(light_checkout)
223
 
             )
224
 
 
225
 
    def test_gather_location_shared_repo_checkout(self):
226
 
        tree = self.make_branch_and_tree('tree')
227
 
        srepo = self.make_repository('shared', shared=True)
228
 
        shared_checkout = tree.branch.create_checkout('shared/checkout')
229
 
        self.assertEqual(
230
 
            [('repository checkout root',
231
 
              shared_checkout.bzrdir.root_transport.base),
232
 
             ('checkout of branch', tree.bzrdir.root_transport.base),
233
 
             ('shared repository', srepo.bzrdir.root_transport.base)],
234
 
             self.gather_tree_location_info(shared_checkout))
235
 
 
236
 
    def gather_tree_location_info(self, tree):
237
 
        return info.gather_location_info(tree.branch.repository, tree.branch,
238
 
                                         tree)
239
 
 
240
 
    def test_gather_location_bound(self):
241
 
        branch = self.make_branch('branch')
242
 
        bound_branch = self.make_branch('bound_branch')
243
 
        bound_branch.bind(branch)
244
 
        self.assertEqual(
245
 
            [('branch root', bound_branch.bzrdir.root_transport.base),
246
 
             ('bound to branch', branch.bzrdir.root_transport.base)],
247
 
            info.gather_location_info(bound_branch.repository, bound_branch)
248
 
        )
249
 
 
250
 
    def test_location_list(self):
251
 
        locs = info.LocationList('/home/foo')
252
 
        locs.add_url('a', 'file:///home/foo/')
253
 
        locs.add_url('b', 'file:///home/foo/bar/')
254
 
        locs.add_url('c', 'file:///home/bar/bar')
255
 
        locs.add_url('d', 'http://example.com/example/')
256
 
        locs.add_url('e', None)
257
 
        self.assertEqual(locs.locs, [('a', '.'),
258
 
                                     ('b', 'bar'),
259
 
                                     ('c', '/home/bar/bar'),
260
 
                                     ('d', 'http://example.com/example/')])
261
 
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
262
 
                             '  d: http://example.com/example/\n',
263
 
                             ''.join(locs.get_lines()))
264
 
 
265
 
    def test_gather_related_braches(self):
266
 
        branch = self.make_branch('.')
267
 
        branch.set_public_branch('baz')
268
 
        branch.set_push_location('bar')
269
 
        branch.set_parent('foo')
270
 
        branch.set_submit_branch('qux')
271
 
        self.assertEqual(
272
 
            [('public branch', 'baz'), ('push branch', 'bar'),
273
 
             ('parent branch', 'foo'), ('submit branch', 'qux')],
274
 
            info._gather_related_branches(branch).locs)