1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
19
branch as _mod_branch,
24
repository as _mod_repository,
28
class TestInfo(tests.TestCaseWithTransport):
30
def test_describe_standalone_layout(self):
31
tree = self.make_branch_and_tree('tree')
32
self.assertEqual('Empty control directory', info.describe_layout())
33
self.assertEqual('Unshared repository with trees',
34
info.describe_layout(tree.branch.repository))
35
tree.branch.repository.set_make_working_trees(False)
36
self.assertEqual('Unshared repository',
37
info.describe_layout(tree.branch.repository))
38
self.assertEqual('Standalone branch',
39
info.describe_layout(tree.branch.repository, tree.branch))
40
self.assertEqual('Standalone branchless tree',
41
info.describe_layout(tree.branch.repository, None, tree))
42
self.assertEqual('Standalone tree',
43
info.describe_layout(tree.branch.repository, tree.branch, tree))
44
tree.branch.bind(tree.branch)
45
self.assertEqual('Bound branch',
46
info.describe_layout(tree.branch.repository, tree.branch))
47
self.assertEqual('Checkout',
48
info.describe_layout(tree.branch.repository, tree.branch, tree))
49
checkout = tree.branch.create_checkout('checkout', lightweight=True)
50
self.assertEqual('Lightweight checkout',
51
info.describe_layout(checkout.branch.repository, checkout.branch,
54
def test_describe_repository_layout(self):
55
repository = self.make_repository('.', shared=True)
56
tree = bzrdir.BzrDir.create_branch_convenience('tree',
57
force_new_tree=True).bzrdir.open_workingtree()
58
self.assertEqual('Shared repository with trees',
59
info.describe_layout(tree.branch.repository))
60
repository.set_make_working_trees(False)
61
self.assertEqual('Shared repository',
62
info.describe_layout(tree.branch.repository))
63
self.assertEqual('Repository branch',
64
info.describe_layout(tree.branch.repository, tree.branch))
65
self.assertEqual('Repository branchless tree',
66
info.describe_layout(tree.branch.repository, None, tree))
67
self.assertEqual('Repository tree',
68
info.describe_layout(tree.branch.repository, tree.branch, tree))
69
tree.branch.bind(tree.branch)
70
self.assertEqual('Repository checkout',
71
info.describe_layout(tree.branch.repository, tree.branch, tree))
72
checkout = tree.branch.create_checkout('checkout', lightweight=True)
73
self.assertEqual('Lightweight checkout',
74
info.describe_layout(checkout.branch.repository, checkout.branch,
77
def assertTreeDescription(self, format):
78
"""Assert a tree's format description matches expectations"""
79
self.make_branch_and_tree('%s_tree' % format, format=format)
80
tree = workingtree.WorkingTree.open('%s_tree' % format)
81
self.assertEqual(format, info.describe_format(tree.bzrdir,
82
tree.branch.repository, tree.branch, tree))
84
def assertCheckoutDescription(self, format, expected=None):
85
"""Assert a checkout's format description matches expectations"""
88
branch = self.make_branch('%s_cobranch' % format, format=format)
89
# this ought to be easier...
90
branch.create_checkout('%s_co' % format,
91
lightweight=True).bzrdir.destroy_workingtree()
92
control = bzrdir.BzrDir.open('%s_co' % format)
93
old_format = control._format.workingtree_format
95
control._format.workingtree_format = \
96
bzrdir.format_registry.make_bzrdir(format).workingtree_format
97
control.create_workingtree()
98
tree = workingtree.WorkingTree.open('%s_co' % format)
99
self.assertEqual(expected, info.describe_format(tree.bzrdir,
100
tree.branch.repository, tree.branch, tree))
102
control._format.workingtree_format = old_format
104
def assertBranchDescription(self, format, expected=None):
105
"""Assert branch's format description matches expectations"""
108
self.make_branch('%s_branch' % format, format=format)
109
branch = _mod_branch.Branch.open('%s_branch' % format)
110
self.assertEqual(expected, info.describe_format(branch.bzrdir,
111
branch.repository, branch, None))
113
def assertRepoDescription(self, format, expected=None):
114
"""Assert repository's format description matches expectations"""
117
self.make_repository('%s_repo' % format, format=format)
118
repo = _mod_repository.Repository.open('%s_repo' % format)
119
self.assertEqual(expected, info.describe_format(repo.bzrdir,
122
def test_describe_tree_format(self):
123
for key in bzrdir.format_registry.keys():
126
self.assertTreeDescription(key)
128
def test_describe_checkout_format(self):
129
for key in bzrdir.format_registry.keys():
130
if key in ('default', 'weave'):
133
if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
134
expected = 'dirstate or dirstate-tags'
135
if key in ('knit', 'metaweave'):
136
expected = 'knit or metaweave'
137
self.assertCheckoutDescription(key, expected)
139
def test_describe_branch_format(self):
140
for key in bzrdir.format_registry.keys():
144
if key in ('dirstate', 'knit'):
145
expected = 'dirstate or knit'
146
self.assertBranchDescription(key, expected)
148
def test_describe_repo_format(self):
149
for key in bzrdir.format_registry.keys():
153
if key in ('dirstate', 'knit', 'dirstate-tags'):
154
expected = 'dirstate or dirstate-tags or knit'
155
self.assertRepoDescription(key, expected)
157
format = bzrdir.format_registry.make_bzrdir('metaweave')
158
format.set_branch_format(_mod_branch.BzrBranchFormat6())
159
tree = self.make_branch_and_tree('unknown', format=format)
160
self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
161
tree.branch.repository, tree.branch, tree))
163
def test_gather_location_standalone(self):
164
tree = self.make_branch_and_tree('tree')
165
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
166
info.gather_location_info(tree.branch.repository, tree.branch,
168
self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
169
info.gather_location_info(tree.branch.repository, tree.branch))
172
def test_gather_location_repo(self):
173
srepo = self.make_repository('shared', shared=True)
174
self.assertEqual([('shared repository',
175
srepo.bzrdir.root_transport.base)],
176
info.gather_location_info(srepo))
177
urepo = self.make_repository('unshared')
178
self.assertEqual([('repository',
179
urepo.bzrdir.root_transport.base)],
180
info.gather_location_info(urepo))
182
def test_gather_location_repo_branch(self):
183
srepo = self.make_repository('shared', shared=True)
184
self.assertEqual([('shared repository',
185
srepo.bzrdir.root_transport.base)],
186
info.gather_location_info(srepo))
187
tree = self.make_branch_and_tree('shared/tree')
188
self.assertEqual([('shared repository',
189
srepo.bzrdir.root_transport.base),
190
('repository branch', 'tree')],
191
info.gather_location_info(srepo, tree.branch, tree))
193
def test_gather_location_light_checkout(self):
194
tree = self.make_branch_and_tree('tree')
195
lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
197
[('light checkout root', lcheckout.bzrdir.root_transport.base),
198
('checkout of branch', tree.bzrdir.root_transport.base)],
199
self.gather_tree_location_info(lcheckout))
201
def test_gather_location_heavy_checkout(self):
202
tree = self.make_branch_and_tree('tree')
203
checkout = tree.branch.create_checkout('checkout')
205
[('checkout root', checkout.bzrdir.root_transport.base),
206
('checkout of branch', tree.bzrdir.root_transport.base)],
207
self.gather_tree_location_info(checkout))
208
light_checkout = checkout.branch.create_checkout('light_checkout',
211
[('light checkout root',
212
light_checkout.bzrdir.root_transport.base),
213
('checkout root', checkout.bzrdir.root_transport.base),
214
('checkout of branch', tree.bzrdir.root_transport.base)],
215
self.gather_tree_location_info(light_checkout)
218
def test_gather_location_shared_repo_checkout(self):
219
tree = self.make_branch_and_tree('tree')
220
srepo = self.make_repository('shared', shared=True)
221
shared_checkout = tree.branch.create_checkout('shared/checkout')
223
[('repository checkout root',
224
shared_checkout.bzrdir.root_transport.base),
225
('checkout of branch', tree.bzrdir.root_transport.base),
226
('shared repository', srepo.bzrdir.root_transport.base)],
227
self.gather_tree_location_info(shared_checkout))
229
def gather_tree_location_info(self, tree):
230
return info.gather_location_info(tree.branch.repository, tree.branch,
233
def test_gather_location_bound(self):
234
branch = self.make_branch('branch')
235
bound_branch = self.make_branch('bound_branch')
236
bound_branch.bind(branch)
238
[('branch root', bound_branch.bzrdir.root_transport.base),
239
('bound to branch', branch.bzrdir.root_transport.base)],
240
info.gather_location_info(bound_branch.repository, bound_branch)