/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2363.5.11 by Aaron Bentley
All info tests pass
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
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
17
from urllib import quote
2363.5.11 by Aaron Bentley
All info tests pass
18
2363.5.2 by Aaron Bentley
Implement layout description
19
from bzrlib import (
2363.5.5 by Aaron Bentley
add info.describe_format
20
    branch as _mod_branch,
2363.5.2 by Aaron Bentley
Implement layout description
21
    bzrdir,
22
    info,
23
    tests,
2363.5.5 by Aaron Bentley
add info.describe_format
24
    workingtree,
25
    repository as _mod_repository,
2363.5.2 by Aaron Bentley
Implement layout description
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)
2363.5.4 by Aaron Bentley
Eliminate the concept of a 'repository lightweight checkout'
74
        self.assertEqual('Lightweight checkout',
2363.5.2 by Aaron Bentley
Implement layout description
75
            info.describe_layout(checkout.branch.repository, checkout.branch,
76
                                 checkout))
2363.5.5 by Aaron Bentley
add info.describe_format
77
78
    def assertTreeDescription(self, format):
2363.5.22 by Aaron Bentley
Restructure tests
79
        """Assert a tree's format description matches expectations"""
2363.5.6 by Aaron Bentley
Add short format description
80
        self.make_branch_and_tree('%s_tree' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_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
2363.5.6 by Aaron Bentley
Add short format description
85
    def assertCheckoutDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
86
        """Assert a checkout's format description matches expectations"""
2363.5.6 by Aaron Bentley
Add short format description
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)
2363.5.13 by Aaron Bentley
Fix environment pollution with assertCheckoutDescription
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
            self.assertEqual(expected, info.describe_format(tree.bzrdir,
101
                tree.branch.repository, tree.branch, tree))
102
        finally:
103
            control._format.workingtree_format = old_format
2363.5.6 by Aaron Bentley
Add short format description
104
2363.5.5 by Aaron Bentley
add info.describe_format
105
    def assertBranchDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
106
        """Assert branch's format description matches expectations"""
2363.5.5 by Aaron Bentley
add info.describe_format
107
        if expected is None:
108
            expected = format
2363.5.6 by Aaron Bentley
Add short format description
109
        self.make_branch('%s_branch' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_format
110
        branch = _mod_branch.Branch.open('%s_branch' % format)
111
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
112
            branch.repository, branch, None))
113
114
    def assertRepoDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
115
        """Assert repository's format description matches expectations"""
2363.5.5 by Aaron Bentley
add info.describe_format
116
        if expected is None:
117
            expected = format
2363.5.6 by Aaron Bentley
Add short format description
118
        self.make_repository('%s_repo' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_format
119
        repo = _mod_repository.Repository.open('%s_repo' % format)
120
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
121
            repo, None, None))
122
2363.5.22 by Aaron Bentley
Restructure tests
123
    def test_describe_tree_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
124
        for key in bzrdir.format_registry.keys():
125
            if key == 'default':
126
                continue
127
            self.assertTreeDescription(key)
128
2363.5.22 by Aaron Bentley
Restructure tests
129
    def test_describe_checkout_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
130
        for key in bzrdir.format_registry.keys():
2363.5.6 by Aaron Bentley
Add short format description
131
            if key in ('default', 'weave'):
132
                continue
133
            expected = None
134
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
135
                expected = 'dirstate or dirstate-tags'
2363.5.6 by Aaron Bentley
Add short format description
136
            if key in ('knit', 'metaweave'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
137
                expected = 'knit or metaweave'
2363.5.6 by Aaron Bentley
Add short format description
138
            self.assertCheckoutDescription(key, expected)
139
2363.5.22 by Aaron Bentley
Restructure tests
140
    def test_describe_branch_format(self):
2363.5.6 by Aaron Bentley
Add short format description
141
        for key in bzrdir.format_registry.keys():
2363.5.5 by Aaron Bentley
add info.describe_format
142
            if key == 'default':
143
                continue
144
            expected = None
145
            if key in ('dirstate', 'knit'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
146
                expected = 'dirstate or knit'
2363.5.5 by Aaron Bentley
add info.describe_format
147
            self.assertBranchDescription(key, expected)
148
2363.5.22 by Aaron Bentley
Restructure tests
149
    def test_describe_repo_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
150
        for key in bzrdir.format_registry.keys():
151
            if key == 'default':
152
                continue
153
            expected = None
154
            if key in ('dirstate', 'knit', 'dirstate-tags'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
155
                expected = 'dirstate or dirstate-tags or knit'
2363.5.5 by Aaron Bentley
add info.describe_format
156
            self.assertRepoDescription(key, expected)
157
158
        format = bzrdir.format_registry.make_bzrdir('metaweave')
159
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
160
        tree = self.make_branch_and_tree('unknown', format=format)
161
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
162
            tree.branch.repository, tree.branch, tree))
2363.5.18 by Aaron Bentley
Get all tests passing
163
164
    def test_gather_location_standalone(self):
165
        tree = self.make_branch_and_tree('tree')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
166
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
167
            info.gather_location_info(tree.branch.repository, tree.branch,
168
                                      tree))
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
169
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
170
            info.gather_location_info(tree.branch.repository, tree.branch))
171
        return tree
172
173
    def test_gather_location_repo(self):
174
        srepo = self.make_repository('shared', shared=True)
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
175
        self.assertEqual([('shared repository',
176
                          srepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
177
                          info.gather_location_info(srepo))
178
        urepo = self.make_repository('unshared')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
179
        self.assertEqual([('repository',
180
                          urepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
181
                          info.gather_location_info(urepo))
182
183
    def test_gather_location_repo_branch(self):
184
        srepo = self.make_repository('shared', shared=True)
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
185
        self.assertEqual([('shared repository',
186
                          srepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
187
                          info.gather_location_info(srepo))
188
        tree = self.make_branch_and_tree('shared/tree')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
189
        self.assertEqual([('shared repository',
190
                          srepo.bzrdir.root_transport.base),
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
191
                          ('repository branch', tree.branch.base)],
2363.5.25 by Aaron Bentley
Update deprecations to 0.18.0
192
                          info.gather_location_info(srepo, tree.branch, tree))
2363.5.18 by Aaron Bentley
Get all tests passing
193
2363.5.22 by Aaron Bentley
Restructure tests
194
    def test_gather_location_light_checkout(self):
2363.5.18 by Aaron Bentley
Get all tests passing
195
        tree = self.make_branch_and_tree('tree')
196
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
197
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
198
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
199
             ('checkout of branch', tree.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
200
            self.gather_tree_location_info(lcheckout))
201
202
    def test_gather_location_heavy_checkout(self):
203
        tree = self.make_branch_and_tree('tree')
204
        checkout = tree.branch.create_checkout('checkout')
205
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
206
            [('checkout root', checkout.bzrdir.root_transport.base),
207
             ('checkout of branch', tree.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
208
            self.gather_tree_location_info(checkout))
209
        light_checkout = checkout.branch.create_checkout('light_checkout',
210
                                                         lightweight=True)
211
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
212
            [('light checkout root',
213
              light_checkout.bzrdir.root_transport.base),
214
             ('checkout root', checkout.bzrdir.root_transport.base),
215
             ('checkout of branch', tree.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
216
             self.gather_tree_location_info(light_checkout)
217
             )
218
219
    def test_gather_location_shared_repo_checkout(self):
220
        tree = self.make_branch_and_tree('tree')
2363.5.18 by Aaron Bentley
Get all tests passing
221
        srepo = self.make_repository('shared', shared=True)
2363.5.22 by Aaron Bentley
Restructure tests
222
        shared_checkout = tree.branch.create_checkout('shared/checkout')
2363.5.18 by Aaron Bentley
Get all tests passing
223
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
224
            [('repository checkout root',
225
              shared_checkout.bzrdir.root_transport.base),
226
             ('checkout of branch', tree.bzrdir.root_transport.base),
227
             ('shared repository', srepo.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
228
             self.gather_tree_location_info(shared_checkout))
229
230
    def gather_tree_location_info(self, tree):
231
        return info.gather_location_info(tree.branch.repository, tree.branch,
232
                                         tree)
2363.5.19 by Aaron Bentley
Add support for bound branches
233
234
    def test_gather_location_bound(self):
235
        branch = self.make_branch('branch')
236
        bound_branch = self.make_branch('bound_branch')
237
        bound_branch.bind(branch)
238
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
239
            [('branch root', bound_branch.bzrdir.root_transport.base),
240
             ('bound to branch', branch.bzrdir.root_transport.base)],
2363.5.19 by Aaron Bentley
Add support for bound branches
241
            info.gather_location_info(bound_branch.repository, bound_branch)
242
        )
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
243
244
    def test_location_list(self):
245
        locs = info.LocationList('/home/foo')
246
        locs.add_url('a', 'file:///home/foo/')
247
        locs.add_url('b', 'file:///home/foo/bar/')
248
        locs.add_url('c', 'file:///home/bar/bar')
249
        locs.add_url('d', 'http://example.com/example/')
250
        locs.add_url('e', None)
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
251
        self.assertEqual(locs.locs, [('a', '.'),
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
252
                                     ('b', 'bar'),
253
                                     ('c', '/home/bar/bar'),
254
                                     ('d', 'http://example.com/example/')])
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
255
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
256
                             '  d: http://example.com/example/\n',
257
                             ''.join(locs.get_lines()))
1551.15.41 by Aaron Bentley
Make info provide more related brances, and format all branches nicely
258
259
    def test_gather_related_braches(self):
260
        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')
265
        self.assertEqual(
266
            [('public branch', 'baz'), ('push branch', 'bar'),
267
             ('parent branch', 'foo'), ('submit branch', 'qux')],
1551.15.43 by Aaron Bentley
Provide ways of getting at unicode-clean output
268
            info._gather_related_branches(branch).locs)