~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_info.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

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
 
import sys
18
 
from urllib import quote
19
 
 
20
 
from bzrlib import (
21
 
    branch as _mod_branch,
22
 
    bzrdir,
23
 
    info,
24
 
    tests,
25
 
    workingtree,
26
 
    repository as _mod_repository,
27
 
    )
28
 
 
29
 
 
30
 
class TestInfo(tests.TestCaseWithTransport):
31
 
 
32
 
    def test_describe_standalone_layout(self):
33
 
        tree = self.make_branch_and_tree('tree')
34
 
        self.assertEqual('Empty control directory', info.describe_layout())
35
 
        self.assertEqual('Unshared repository with trees',
36
 
            info.describe_layout(tree.branch.repository))
37
 
        tree.branch.repository.set_make_working_trees(False)
38
 
        self.assertEqual('Unshared repository',
39
 
            info.describe_layout(tree.branch.repository))
40
 
        self.assertEqual('Standalone branch',
41
 
            info.describe_layout(tree.branch.repository, tree.branch))
42
 
        self.assertEqual('Standalone branchless tree',
43
 
            info.describe_layout(tree.branch.repository, None, tree))
44
 
        self.assertEqual('Standalone tree',
45
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
46
 
        tree.branch.bind(tree.branch)
47
 
        self.assertEqual('Bound branch',
48
 
            info.describe_layout(tree.branch.repository, tree.branch))
49
 
        self.assertEqual('Checkout',
50
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
51
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
52
 
        self.assertEqual('Lightweight checkout',
53
 
            info.describe_layout(checkout.branch.repository, checkout.branch,
54
 
                                 checkout))
55
 
 
56
 
    def test_describe_repository_layout(self):
57
 
        repository = self.make_repository('.', shared=True)
58
 
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
59
 
            force_new_tree=True).bzrdir.open_workingtree()
60
 
        self.assertEqual('Shared repository with trees',
61
 
            info.describe_layout(tree.branch.repository))
62
 
        repository.set_make_working_trees(False)
63
 
        self.assertEqual('Shared repository',
64
 
            info.describe_layout(tree.branch.repository))
65
 
        self.assertEqual('Repository branch',
66
 
            info.describe_layout(tree.branch.repository, tree.branch))
67
 
        self.assertEqual('Repository branchless tree',
68
 
            info.describe_layout(tree.branch.repository, None, tree))
69
 
        self.assertEqual('Repository tree',
70
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
71
 
        tree.branch.bind(tree.branch)
72
 
        self.assertEqual('Repository checkout',
73
 
            info.describe_layout(tree.branch.repository, tree.branch, tree))
74
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
75
 
        self.assertEqual('Lightweight checkout',
76
 
            info.describe_layout(checkout.branch.repository, checkout.branch,
77
 
                                 checkout))
78
 
 
79
 
    def assertTreeDescription(self, format):
80
 
        """Assert a tree's format description matches expectations"""
81
 
        self.make_branch_and_tree('%s_tree' % format, format=format)
82
 
        tree = workingtree.WorkingTree.open('%s_tree' % format)
83
 
        self.assertEqual(format, info.describe_format(tree.bzrdir,
84
 
            tree.branch.repository, tree.branch, tree))
85
 
 
86
 
    def assertCheckoutDescription(self, format, expected=None):
87
 
        """Assert a checkout's format description matches expectations"""
88
 
        if expected is None:
89
 
            expected = format
90
 
        branch = self.make_branch('%s_cobranch' % format, format=format)
91
 
        # this ought to be easier...
92
 
        branch.create_checkout('%s_co' % format,
93
 
            lightweight=True).bzrdir.destroy_workingtree()
94
 
        control = bzrdir.BzrDir.open('%s_co' % format)
95
 
        old_format = control._format.workingtree_format
96
 
        try:
97
 
            control._format.workingtree_format = \
98
 
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
99
 
            control.create_workingtree()
100
 
            tree = workingtree.WorkingTree.open('%s_co' % format)
101
 
            format_description = info.describe_format(tree.bzrdir,
102
 
                    tree.branch.repository, tree.branch, tree)
103
 
            self.assertEqual(expected, format_description,
104
 
                "checkout of format called %r was described as %r" %
105
 
                (expected, format_description))
106
 
        finally:
107
 
            control._format.workingtree_format = old_format
108
 
 
109
 
    def assertBranchDescription(self, format, expected=None):
110
 
        """Assert branch's format description matches expectations"""
111
 
        if expected is None:
112
 
            expected = format
113
 
        self.make_branch('%s_branch' % format, format=format)
114
 
        branch = _mod_branch.Branch.open('%s_branch' % format)
115
 
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
116
 
            branch.repository, branch, None))
117
 
 
118
 
    def assertRepoDescription(self, format, expected=None):
119
 
        """Assert repository's format description matches expectations"""
120
 
        if expected is None:
121
 
            expected = format
122
 
        self.make_repository('%s_repo' % format, format=format)
123
 
        repo = _mod_repository.Repository.open('%s_repo' % format)
124
 
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
125
 
            repo, None, None))
126
 
 
127
 
    def test_describe_tree_format(self):
128
 
        for key in bzrdir.format_registry.keys():
129
 
            if key in bzrdir.format_registry.aliases():
130
 
                continue
131
 
            self.assertTreeDescription(key)
132
 
 
133
 
    def test_describe_checkout_format(self):
134
 
        for key in bzrdir.format_registry.keys():
135
 
            if key in bzrdir.format_registry.aliases():
136
 
                # Aliases will not describe correctly in the UI because the
137
 
                # real format is found.
138
 
                continue
139
 
            # legacy: weave does not support checkouts
140
 
            if key == 'weave':
141
 
                continue
142
 
            if bzrdir.format_registry.get_info(key).experimental:
143
 
                # We don't require that experimental formats support checkouts
144
 
                # or describe correctly in the UI.
145
 
                continue
146
 
            expected = None
147
 
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
148
 
                'pack-0.92', 'pack-0.92-subtree', 'rich-root',
149
 
                'rich-root-pack'):
150
 
                expected = 'dirstate or dirstate-tags or pack-0.92 or'\
151
 
                    ' rich-root or rich-root-pack'
152
 
            if key in ('knit', 'metaweave'):
153
 
                expected = 'knit or metaweave'
154
 
            self.assertCheckoutDescription(key, expected)
155
 
 
156
 
    def test_describe_branch_format(self):
157
 
        for key in bzrdir.format_registry.keys():
158
 
            if key in bzrdir.format_registry.aliases():
159
 
                continue
160
 
            expected = None
161
 
            if key in ('dirstate', 'knit'):
162
 
                expected = 'dirstate or knit'
163
 
            self.assertBranchDescription(key, expected)
164
 
 
165
 
    def test_describe_repo_format(self):
166
 
        for key in bzrdir.format_registry.keys():
167
 
            if key in bzrdir.format_registry.aliases():
168
 
                continue
169
 
            expected = None
170
 
            if key in ('dirstate', 'knit', 'dirstate-tags'):
171
 
                expected = 'dirstate or dirstate-tags or knit'
172
 
            self.assertRepoDescription(key, expected)
173
 
 
174
 
        format = bzrdir.format_registry.make_bzrdir('metaweave')
175
 
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
176
 
        tree = self.make_branch_and_tree('unknown', format=format)
177
 
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
178
 
            tree.branch.repository, tree.branch, tree))
179
 
 
180
 
    def test_gather_location_standalone(self):
181
 
        tree = self.make_branch_and_tree('tree')
182
 
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
183
 
            info.gather_location_info(tree.branch.repository, tree.branch,
184
 
                                      tree))
185
 
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
186
 
            info.gather_location_info(tree.branch.repository, tree.branch))
187
 
        return tree
188
 
 
189
 
    def test_gather_location_repo(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
 
        urepo = self.make_repository('unshared')
195
 
        self.assertEqual([('repository',
196
 
                          urepo.bzrdir.root_transport.base)],
197
 
                          info.gather_location_info(urepo))
198
 
 
199
 
    def test_gather_location_repo_branch(self):
200
 
        srepo = self.make_repository('shared', shared=True)
201
 
        self.assertEqual([('shared repository',
202
 
                          srepo.bzrdir.root_transport.base)],
203
 
                          info.gather_location_info(srepo))
204
 
        tree = self.make_branch_and_tree('shared/tree')
205
 
        self.assertEqual([('shared repository',
206
 
                          srepo.bzrdir.root_transport.base),
207
 
                          ('repository branch', tree.branch.base)],
208
 
                          info.gather_location_info(srepo, tree.branch, tree))
209
 
 
210
 
    def test_gather_location_light_checkout(self):
211
 
        tree = self.make_branch_and_tree('tree')
212
 
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
213
 
        self.assertEqual(
214
 
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
215
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
216
 
            self.gather_tree_location_info(lcheckout))
217
 
 
218
 
    def test_gather_location_heavy_checkout(self):
219
 
        tree = self.make_branch_and_tree('tree')
220
 
        checkout = tree.branch.create_checkout('checkout')
221
 
        self.assertEqual(
222
 
            [('checkout root', checkout.bzrdir.root_transport.base),
223
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
224
 
            self.gather_tree_location_info(checkout))
225
 
        light_checkout = checkout.branch.create_checkout('light_checkout',
226
 
                                                         lightweight=True)
227
 
        self.assertEqual(
228
 
            [('light checkout root',
229
 
              light_checkout.bzrdir.root_transport.base),
230
 
             ('checkout root', checkout.bzrdir.root_transport.base),
231
 
             ('checkout of branch', tree.bzrdir.root_transport.base)],
232
 
             self.gather_tree_location_info(light_checkout)
233
 
             )
234
 
 
235
 
    def test_gather_location_shared_repo_checkout(self):
236
 
        tree = self.make_branch_and_tree('tree')
237
 
        srepo = self.make_repository('shared', shared=True)
238
 
        shared_checkout = tree.branch.create_checkout('shared/checkout')
239
 
        self.assertEqual(
240
 
            [('repository checkout root',
241
 
              shared_checkout.bzrdir.root_transport.base),
242
 
             ('checkout of branch', tree.bzrdir.root_transport.base),
243
 
             ('shared repository', srepo.bzrdir.root_transport.base)],
244
 
             self.gather_tree_location_info(shared_checkout))
245
 
 
246
 
    def gather_tree_location_info(self, tree):
247
 
        return info.gather_location_info(tree.branch.repository, tree.branch,
248
 
                                         tree)
249
 
 
250
 
    def test_gather_location_bound(self):
251
 
        branch = self.make_branch('branch')
252
 
        bound_branch = self.make_branch('bound_branch')
253
 
        bound_branch.bind(branch)
254
 
        self.assertEqual(
255
 
            [('branch root', bound_branch.bzrdir.root_transport.base),
256
 
             ('bound to branch', branch.bzrdir.root_transport.base)],
257
 
            info.gather_location_info(bound_branch.repository, bound_branch)
258
 
        )
259
 
 
260
 
    def test_location_list(self):
261
 
        if sys.platform == 'win32':
262
 
            raise tests.TestSkipped('Windows-unfriendly test')
263
 
        locs = info.LocationList('/home/foo')
264
 
        locs.add_url('a', 'file:///home/foo/')
265
 
        locs.add_url('b', 'file:///home/foo/bar/')
266
 
        locs.add_url('c', 'file:///home/bar/bar')
267
 
        locs.add_url('d', 'http://example.com/example/')
268
 
        locs.add_url('e', None)
269
 
        self.assertEqual(locs.locs, [('a', '.'),
270
 
                                     ('b', 'bar'),
271
 
                                     ('c', '/home/bar/bar'),
272
 
                                     ('d', 'http://example.com/example/')])
273
 
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
274
 
                             '  d: http://example.com/example/\n',
275
 
                             ''.join(locs.get_lines()))
276
 
 
277
 
    def test_gather_related_braches(self):
278
 
        branch = self.make_branch('.')
279
 
        branch.set_public_branch('baz')
280
 
        branch.set_push_location('bar')
281
 
        branch.set_parent('foo')
282
 
        branch.set_submit_branch('qux')
283
 
        self.assertEqual(
284
 
            [('public branch', 'baz'), ('push branch', 'bar'),
285
 
             ('parent branch', 'foo'), ('submit branch', 'qux')],
286
 
            info._gather_related_branches(branch).locs)