~bzr-pqm/bzr/bzr.dev

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
17
2363.5.2 by Aaron Bentley
Implement layout description
18
from bzrlib import (
2363.5.5 by Aaron Bentley
add info.describe_format
19
    branch as _mod_branch,
2363.5.2 by Aaron Bentley
Implement layout description
20
    bzrdir,
21
    info,
22
    tests,
2363.5.5 by Aaron Bentley
add info.describe_format
23
    workingtree,
24
    repository as _mod_repository,
2363.5.2 by Aaron Bentley
Implement layout description
25
    )
26
27
28
class TestInfo(tests.TestCaseWithTransport):
29
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,
52
                                 checkout))
53
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)
2363.5.4 by Aaron Bentley
Eliminate the concept of a 'repository lightweight checkout'
73
        self.assertEqual('Lightweight checkout',
2363.5.2 by Aaron Bentley
Implement layout description
74
            info.describe_layout(checkout.branch.repository, checkout.branch,
75
                                 checkout))
2363.5.5 by Aaron Bentley
add info.describe_format
76
77
    def assertTreeDescription(self, format):
2363.5.22 by Aaron Bentley
Restructure tests
78
        """Assert a tree's format description matches expectations"""
2363.5.6 by Aaron Bentley
Add short format description
79
        self.make_branch_and_tree('%s_tree' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_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))
83
2363.5.6 by Aaron Bentley
Add short format description
84
    def assertCheckoutDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
85
        """Assert a checkout's format description matches expectations"""
2363.5.6 by Aaron Bentley
Add short format description
86
        if expected is None:
87
            expected = format
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)
2363.5.13 by Aaron Bentley
Fix environment pollution with assertCheckoutDescription
93
        old_format = control._format.workingtree_format
94
        try:
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))
101
        finally:
102
            control._format.workingtree_format = old_format
2363.5.6 by Aaron Bentley
Add short format description
103
2363.5.5 by Aaron Bentley
add info.describe_format
104
    def assertBranchDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
105
        """Assert branch's format description matches expectations"""
2363.5.5 by Aaron Bentley
add info.describe_format
106
        if expected is None:
107
            expected = format
2363.5.6 by Aaron Bentley
Add short format description
108
        self.make_branch('%s_branch' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_format
109
        branch = _mod_branch.Branch.open('%s_branch' % format)
110
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
111
            branch.repository, branch, None))
112
113
    def assertRepoDescription(self, format, expected=None):
2363.5.22 by Aaron Bentley
Restructure tests
114
        """Assert repository's format description matches expectations"""
2363.5.5 by Aaron Bentley
add info.describe_format
115
        if expected is None:
116
            expected = format
2363.5.6 by Aaron Bentley
Add short format description
117
        self.make_repository('%s_repo' % format, format=format)
2363.5.5 by Aaron Bentley
add info.describe_format
118
        repo = _mod_repository.Repository.open('%s_repo' % format)
119
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
120
            repo, None, None))
121
2363.5.22 by Aaron Bentley
Restructure tests
122
    def test_describe_tree_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
123
        for key in bzrdir.format_registry.keys():
124
            if key == 'default':
125
                continue
126
            self.assertTreeDescription(key)
127
2363.5.22 by Aaron Bentley
Restructure tests
128
    def test_describe_checkout_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
129
        for key in bzrdir.format_registry.keys():
2363.5.6 by Aaron Bentley
Add short format description
130
            if key in ('default', 'weave'):
131
                continue
132
            expected = None
133
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
134
                expected = 'dirstate or dirstate-tags'
2363.5.6 by Aaron Bentley
Add short format description
135
            if key in ('knit', 'metaweave'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
136
                expected = 'knit or metaweave'
2363.5.6 by Aaron Bentley
Add short format description
137
            self.assertCheckoutDescription(key, expected)
138
2363.5.22 by Aaron Bentley
Restructure tests
139
    def test_describe_branch_format(self):
2363.5.6 by Aaron Bentley
Add short format description
140
        for key in bzrdir.format_registry.keys():
2363.5.5 by Aaron Bentley
add info.describe_format
141
            if key == 'default':
142
                continue
143
            expected = None
144
            if key in ('dirstate', 'knit'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
145
                expected = 'dirstate or knit'
2363.5.5 by Aaron Bentley
add info.describe_format
146
            self.assertBranchDescription(key, expected)
147
2363.5.22 by Aaron Bentley
Restructure tests
148
    def test_describe_repo_format(self):
2363.5.5 by Aaron Bentley
add info.describe_format
149
        for key in bzrdir.format_registry.keys():
150
            if key == 'default':
151
                continue
152
            expected = None
153
            if key in ('dirstate', 'knit', 'dirstate-tags'):
2363.5.17 by Aaron Bentley
Change separator from '/' to 'or'
154
                expected = 'dirstate or dirstate-tags or knit'
2363.5.5 by Aaron Bentley
add info.describe_format
155
            self.assertRepoDescription(key, expected)
156
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))
2363.5.18 by Aaron Bentley
Get all tests passing
162
163
    def test_gather_location_standalone(self):
164
        tree = self.make_branch_and_tree('tree')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
165
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
166
            info.gather_location_info(tree.branch.repository, tree.branch,
167
                                      tree))
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
168
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
169
            info.gather_location_info(tree.branch.repository, tree.branch))
170
        return tree
171
172
    def test_gather_location_repo(self):
173
        srepo = self.make_repository('shared', shared=True)
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
174
        self.assertEqual([('shared repository',
175
                          srepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
176
                          info.gather_location_info(srepo))
177
        urepo = self.make_repository('unshared')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
178
        self.assertEqual([('repository',
179
                          urepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
180
                          info.gather_location_info(urepo))
181
182
    def test_gather_location_repo_branch(self):
183
        srepo = self.make_repository('shared', shared=True)
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
184
        self.assertEqual([('shared repository',
185
                          srepo.bzrdir.root_transport.base)],
2363.5.18 by Aaron Bentley
Get all tests passing
186
                          info.gather_location_info(srepo))
187
        tree = self.make_branch_and_tree('shared/tree')
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
188
        self.assertEqual([('shared repository',
189
                          srepo.bzrdir.root_transport.base),
190
                          ('repository branch', 'tree')],
2363.5.25 by Aaron Bentley
Update deprecations to 0.18.0
191
                          info.gather_location_info(srepo, tree.branch, tree))
2363.5.18 by Aaron Bentley
Get all tests passing
192
2363.5.22 by Aaron Bentley
Restructure tests
193
    def test_gather_location_light_checkout(self):
2363.5.18 by Aaron Bentley
Get all tests passing
194
        tree = self.make_branch_and_tree('tree')
195
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
196
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
197
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
198
             ('checkout of branch', tree.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
199
            self.gather_tree_location_info(lcheckout))
200
201
    def test_gather_location_heavy_checkout(self):
202
        tree = self.make_branch_and_tree('tree')
203
        checkout = tree.branch.create_checkout('checkout')
204
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
205
            [('checkout root', checkout.bzrdir.root_transport.base),
206
             ('checkout of branch', tree.bzrdir.root_transport.base)],
2363.5.22 by Aaron Bentley
Restructure tests
207
            self.gather_tree_location_info(checkout))
208
        light_checkout = checkout.branch.create_checkout('light_checkout',
209
                                                         lightweight=True)
210
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
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)],
2363.5.22 by Aaron Bentley
Restructure tests
215
             self.gather_tree_location_info(light_checkout)
216
             )
217
218
    def test_gather_location_shared_repo_checkout(self):
219
        tree = self.make_branch_and_tree('tree')
2363.5.18 by Aaron Bentley
Get all tests passing
220
        srepo = self.make_repository('shared', shared=True)
2363.5.22 by Aaron Bentley
Restructure tests
221
        shared_checkout = tree.branch.create_checkout('shared/checkout')
2363.5.18 by Aaron Bentley
Get all tests passing
222
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
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)],
2363.5.22 by Aaron Bentley
Restructure tests
227
             self.gather_tree_location_info(shared_checkout))
228
229
    def gather_tree_location_info(self, tree):
230
        return info.gather_location_info(tree.branch.repository, tree.branch,
231
                                         tree)
2363.5.19 by Aaron Bentley
Add support for bound branches
232
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)
237
        self.assertEqual(
2363.5.23 by Aaron Bentley
Output 2-tuples from gather_locations
238
            [('branch root', bound_branch.bzrdir.root_transport.base),
239
             ('bound to branch', branch.bzrdir.root_transport.base)],
2363.5.19 by Aaron Bentley
Add support for bound branches
240
            info.gather_location_info(bound_branch.repository, bound_branch)
241
        )