/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
2
#
1852.6.1 by Robert Collins
Start tree implementation tests.
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.
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
7
#
1852.6.1 by Robert Collins
Start tree implementation tests.
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.
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
12
#
1852.6.1 by Robert Collins
Start tree implementation tests.
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
"""Tree implementation tests for bzr.
19
20
These test the conformance of all the tree variations to the expected API.
21
Specific tests for individual variations are in other places such as:
22
 - tests/test_tree.py
23
 - tests/test_revision.py
24
 - tests/test_workingtree.py
25
 - tests/workingtree_implementations/*.py.
26
"""
27
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
28
from bzrlib import (
29
    errors,
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
30
    tests,
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
31
    transform,
32
    )
1852.6.1 by Robert Collins
Start tree implementation tests.
33
from bzrlib.transport import get_transport
34
from bzrlib.tests import (
35
                          adapt_modules,
36
                          default_transport,
37
                          TestCaseWithTransport,
38
                          TestLoader,
39
                          TestSuite,
40
                          )
41
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
2079.1.1 by John Arbash Meinel
Create a deprecated bzrlib.tree.RevisionTree() in favor of bzrlib.revisiontree.RevisionTree()
42
from bzrlib.revisiontree import RevisionTree
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
43
from bzrlib.workingtree import (
44
    WorkingTreeFormat,
45
    WorkingTreeFormat3,
46
    WorkingTreeTestProviderAdapter,
47
    _legacy_formats,
48
    )
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
49
from bzrlib.workingtree_4 import (
50
    DirStateRevisionTree,
51
    WorkingTreeFormat4,
52
    )
1852.6.1 by Robert Collins
Start tree implementation tests.
53
54
55
def return_parameter(something):
56
    """A trivial thunk to return its input."""
57
    return something
58
59
60
def revision_tree_from_workingtree(tree):
61
    """Create a revision tree from a working tree."""
2100.3.36 by Aaron Bentley
avoid subtree commit when converting a work tree into a revision tree
62
    revid = tree.commit('save tree', allow_pointless=True, recursive=None)
1852.6.1 by Robert Collins
Start tree implementation tests.
63
    return tree.branch.repository.revision_tree(revid)
64
65
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
66
def _dirstate_tree_from_workingtree(tree):
67
    revid = tree.commit('save tree', allow_pointless=True)
68
    return tree.basis_tree()
69
70
1852.6.1 by Robert Collins
Start tree implementation tests.
71
class TestTreeImplementationSupport(TestCaseWithTransport):
72
73
    def test_revision_tree_from_workingtree(self):
74
        tree = self.make_branch_and_tree('.')
75
        tree = revision_tree_from_workingtree(tree)
76
        self.assertIsInstance(tree, RevisionTree)
77
78
79
class TestCaseWithTree(TestCaseWithBzrDir):
80
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
81
    def make_branch_and_tree(self, relpath):
82
        made_control = self.make_bzrdir(relpath, format=
83
            self.workingtree_format._matchingbzrdir)
1852.6.1 by Robert Collins
Start tree implementation tests.
84
        made_control.create_repository()
85
        made_control.create_branch()
86
        return self.workingtree_format.initialize(made_control)
87
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
88
    def _convert_tree(self, tree, converter=None):
89
        """helper to convert using the converter or a supplied one."""
90
        # convert that to the final shape
91
        if converter is None:
92
            converter = self.workingtree_to_test_tree
93
        return converter(tree)
94
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
95
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
96
        """Make a tree with no parents and no contents from empty_tree.
97
        
98
        :param empty_tree: A working tree with no content and no parents to
99
            modify.
100
        """
1731.1.33 by Aaron Bentley
Revert no-special-root changes
101
        empty_tree.set_root_id('empty-root-id')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
102
        return self._convert_tree(empty_tree, converter)
1852.6.1 by Robert Collins
Start tree implementation tests.
103
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
104
    def _make_abc_tree(self, tree):
105
        """setup an abc content tree."""
106
        files = ['a', 'b/', 'b/c']
2255.2.15 by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing.
107
        self.build_tree(files, line_endings='binary',
1982.1.4 by Alexander Belchenko
tree_implementations tests: build_tree with binary (LF) line-endings
108
                        transport=tree.bzrdir.root_transport)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
109
        tree.set_root_id('root-id')
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
110
        tree.add(files, ['a-id', 'b-id', 'c-id'])
111
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
112
    def get_tree_no_parents_abc_content(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
113
        """return a test tree with a, b/, b/c contents."""
114
        self._make_abc_tree(tree)
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
115
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
116
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
117
    def get_tree_no_parents_abc_content_2(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
118
        """return a test tree with a, b/, b/c contents.
119
        
120
        This variation changes the content of 'a' to foobar\n.
121
        """
122
        self._make_abc_tree(tree)
123
        f = open(tree.basedir + '/a', 'wb')
124
        try:
125
            f.write('foobar\n')
126
        finally:
127
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
128
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
129
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
130
    def get_tree_no_parents_abc_content_3(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
131
        """return a test tree with a, b/, b/c contents.
132
        
133
        This variation changes the executable flag of b/c to True.
134
        """
135
        self._make_abc_tree(tree)
136
        tt = transform.TreeTransform(tree)
137
        trans_id = tt.trans_id_tree_path('b/c')
138
        tt.set_executability(True, trans_id)
139
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
140
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
141
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
142
    def get_tree_no_parents_abc_content_4(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
143
        """return a test tree with d, b/, b/c contents.
144
        
145
        This variation renames a to d.
146
        """
147
        self._make_abc_tree(tree)
148
        tree.rename_one('a', 'd')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
149
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
150
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
151
    def get_tree_no_parents_abc_content_5(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
152
        """return a test tree with d, b/, b/c contents.
153
        
154
        This variation renames a to d and alters its content to 'bar\n'.
155
        """
156
        self._make_abc_tree(tree)
157
        tree.rename_one('a', 'd')
158
        f = open(tree.basedir + '/d', 'wb')
159
        try:
160
            f.write('bar\n')
161
        finally:
162
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
163
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
164
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
165
    def get_tree_no_parents_abc_content_6(self, tree, converter=None):
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
166
        """return a test tree with a, b/, e contents.
167
        
168
        This variation renames b/c to e, and makes it executable.
169
        """
170
        self._make_abc_tree(tree)
171
        tt = transform.TreeTransform(tree)
172
        trans_id = tt.trans_id_tree_path('b/c')
173
        parent_trans_id = tt.trans_id_tree_path('')
174
        tt.adjust_path('e', parent_trans_id, trans_id)
175
        tt.set_executability(True, trans_id)
176
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
177
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
178
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
179
    def get_tree_with_subdirs_and_all_content_types(self):
180
        """Return a test tree with subdirs and all content types.
181
182
        The returned tree has the following inventory:
183
            [('', inventory.ROOT_ID),
184
             ('0file', '2file'),
185
             ('1top-dir', '1top-dir'),
186
             (u'2utf\u1234file', u'0utf\u1234file'),
187
             ('symlink', 'symlink'),
188
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
189
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
190
        where each component has the type of its name - i.e. '1file..' is afile.
191
192
        note that the order of the paths and fileids is deliberately 
193
        mismatched to ensure that the result order is path based.
194
        """
195
        tree = self.make_branch_and_tree('.')
196
        paths = ['0file',
197
            '1top-dir/',
198
            u'2utf\u1234file',
199
            '1top-dir/0file-in-1topdir',
200
            '1top-dir/1dir-in-1topdir/'
201
            ]
202
        ids = [
203
            '2file',
204
            '1top-dir',
2255.2.107 by John Arbash Meinel
(working), fix dirstate to use utf8 file ids.
205
            u'0utf\u1234file'.encode('utf8'),
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
206
            '1file-in-1topdir',
207
            '0dir-in-1topdir'
208
            ]
209
        self.build_tree(paths)
210
        tree.add(paths, ids)
211
        tt = transform.TreeTransform(tree)
212
        root_transaction_id = tt.trans_id_tree_path('')
213
        tt.new_symlink('symlink',
214
            root_transaction_id, 'link-target', 'symlink')
215
        tt.apply()
216
        return self.workingtree_to_test_tree(tree)
217
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
218
    def get_tree_with_utf8(self, tree):
219
        """Generate a tree with a utf8 revision and unicode paths."""
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
220
        self._create_tree_with_utf8(tree)
221
        return self.workingtree_to_test_tree(tree)
222
223
    def _create_tree_with_utf8(self, tree):
224
        """Generate a tree with a utf8 revision and unicode paths."""
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
225
        paths = [u'',
226
                 u'f\xf6',
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
227
                 u'b\xe5r/',
228
                 u'b\xe5r/b\xe1z',
229
                ]
230
        # bzr itself does not create unicode file ids, but we want them for
231
        # testing.
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
232
        file_ids = [u'TREE_ROOT',
2255.2.107 by John Arbash Meinel
(working), fix dirstate to use utf8 file ids.
233
                    u'f\xf6-id'.encode('utf8'),
234
                    u'b\xe5r-id'.encode('utf8'),
235
                    u'b\xe1z-id'.encode('utf8'),
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
236
                   ]
237
        try:
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
238
            self.build_tree(paths[1:])
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
239
        except UnicodeError:
240
            raise tests.TestSkipped('filesystem does not support unicode.')
2255.2.107 by John Arbash Meinel
(working), fix dirstate to use utf8 file ids.
241
        if tree.path2id('') is None:
242
            # Some trees do not have a root yet.
243
            tree.add(paths, file_ids)
244
        else:
245
            # Some trees will already have a root
246
            tree.set_root_id(file_ids[0])
247
            tree.add(paths[1:], file_ids[1:])
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
248
        try:
249
            tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
250
        except errors.NonAsciiRevisionId:
251
            raise tests.TestSkipped('non-ascii revision ids not supported')
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
252
253
    def get_tree_with_merged_utf8(self, tree):
254
        """Generate a tree with utf8 ancestors."""
255
        self._create_tree_with_utf8(tree)
256
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
257
        self.build_tree([u'tree2/b\xe5r/z\xf7z'])
2255.2.107 by John Arbash Meinel
(working), fix dirstate to use utf8 file ids.
258
        tree2.add([u'b\xe5r/z\xf7z'], [u'z\xf7z-id'.encode('utf8')])
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
259
        tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
260
261
        tree.merge_from_branch(tree2.branch)
262
        tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
263
        return self.workingtree_to_test_tree(tree)
264
1852.6.1 by Robert Collins
Start tree implementation tests.
265
266
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
267
    """Generate test suites for each Tree implementation in bzrlib.
268
269
    Currently this covers all working tree formats, and RevisionTree by 
270
    committing a working tree to create the revision tree.
271
    """
272
273
    def adapt(self, test):
274
        result = super(TreeTestProviderAdapter, self).adapt(test)
275
        for adapted_test in result:
276
            # for working tree adapted tests, preserve the tree
277
            adapted_test.workingtree_to_test_tree = return_parameter
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
278
        # this is the default in that it's used to test the generic InterTree
279
        # code.
280
        default_format = WorkingTreeFormat3()
1852.6.1 by Robert Collins
Start tree implementation tests.
281
        revision_tree_test = self._clone_test(
282
            test,
283
            default_format._matchingbzrdir, 
284
            default_format,
285
            RevisionTree.__name__)
286
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
287
        result.addTest(revision_tree_test)
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
288
        # also explicity test WorkingTree4 against everything
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
289
        dirstate_format = WorkingTreeFormat4()
290
        dirstate_revision_tree_test = self._clone_test(
291
            test,
292
            dirstate_format._matchingbzrdir,
293
            dirstate_format,
294
            DirStateRevisionTree.__name__)
295
        dirstate_revision_tree_test.workingtree_to_test_tree = _dirstate_tree_from_workingtree
296
        result.addTest(dirstate_revision_tree_test)
1852.6.1 by Robert Collins
Start tree implementation tests.
297
        return result
298
299
300
def test_suite():
301
    result = TestSuite()
302
    test_tree_implementations = [
2255.7.36 by John Arbash Meinel
All trees should implement get_file_mtime()
303
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
304
        'bzrlib.tests.tree_implementations.test_get_symlink_target',
2255.2.71 by John Arbash Meinel
Add a test for list_files, and implement it for DirStateRevisionTree
305
        'bzrlib.tests.tree_implementations.test_list_files',
1908.11.5 by John Arbash Meinel
[merge] bzr.dev 2240
306
        'bzrlib.tests.tree_implementations.test_revision_tree',
1852.6.1 by Robert Collins
Start tree implementation tests.
307
        'bzrlib.tests.tree_implementations.test_test_trees',
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
308
        'bzrlib.tests.tree_implementations.test_tree',
1852.15.3 by Robert Collins
Add a first-cut Tree.walkdirs method.
309
        'bzrlib.tests.tree_implementations.test_walkdirs',
1852.6.1 by Robert Collins
Start tree implementation tests.
310
        ]
311
    adapter = TreeTestProviderAdapter(
312
        default_transport,
313
        # None here will cause a readonly decorator to be created
314
        # by the TestCaseWithTransport.get_readonly_transport method.
315
        None,
316
        [(format, format._matchingbzrdir) for format in 
317
         WorkingTreeFormat._formats.values() + _legacy_formats])
318
    loader = TestLoader()
319
    adapt_modules(test_tree_implementations, adapter, loader, result)
320
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))
321
    return result