~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

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
 
 
18
from bzrlib import (
 
19
    branch as _mod_branch,
 
20
    bzrdir,
 
21
    info,
 
22
    tests,
 
23
    workingtree,
 
24
    repository as _mod_repository,
 
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)
 
73
        self.assertEqual('Lightweight checkout',
 
74
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
75
                                 checkout))
 
76
 
 
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))
 
83
 
 
84
    def assertCheckoutDescription(self, format, expected=None):
 
85
        """Assert a checkout's format description matches expectations"""
 
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)
 
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
 
103
 
 
104
    def assertBranchDescription(self, format, expected=None):
 
105
        """Assert branch's format description matches expectations"""
 
106
        if expected is None:
 
107
            expected = format
 
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))
 
112
 
 
113
    def assertRepoDescription(self, format, expected=None):
 
114
        """Assert repository's format description matches expectations"""
 
115
        if expected is None:
 
116
            expected = format
 
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,
 
120
            repo, None, None))
 
121
 
 
122
    def test_describe_tree_format(self):
 
123
        for key in bzrdir.format_registry.keys():
 
124
            if key == 'default':
 
125
                continue
 
126
            self.assertTreeDescription(key)
 
127
 
 
128
    def test_describe_checkout_format(self):
 
129
        for key in bzrdir.format_registry.keys():
 
130
            if key in ('default', 'weave'):
 
131
                continue
 
132
            expected = None
 
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)
 
138
 
 
139
    def test_describe_branch_format(self):
 
140
        for key in bzrdir.format_registry.keys():
 
141
            if key == 'default':
 
142
                continue
 
143
            expected = None
 
144
            if key in ('dirstate', 'knit'):
 
145
                expected = 'dirstate or knit'
 
146
            self.assertBranchDescription(key, expected)
 
147
 
 
148
    def test_describe_repo_format(self):
 
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'):
 
154
                expected = 'dirstate or dirstate-tags or knit'
 
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))
 
162
 
 
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,
 
167
                                      tree))
 
168
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
 
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)
 
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))
 
181
 
 
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))
 
192
 
 
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)
 
196
        self.assertEqual(
 
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))
 
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(
 
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',
 
209
                                                         lightweight=True)
 
210
        self.assertEqual(
 
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)
 
216
             )
 
217
 
 
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')
 
222
        self.assertEqual(
 
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))
 
228
 
 
229
    def gather_tree_location_info(self, tree):
 
230
        return info.gather_location_info(tree.branch.repository, tree.branch,
 
231
                                         tree)
 
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(
 
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)
 
241
        )