/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 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,
30
    transform,
31
    )
1852.6.1 by Robert Collins
Start tree implementation tests.
32
from bzrlib.transport import get_transport
33
from bzrlib.tests import (
34
                          adapt_modules,
35
                          default_transport,
36
                          TestCaseWithTransport,
37
                          TestLoader,
38
                          TestSuite,
39
                          )
40
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()
41
from bzrlib.revisiontree import RevisionTree
1852.6.1 by Robert Collins
Start tree implementation tests.
42
from bzrlib.workingtree import (WorkingTreeFormat,
43
                                WorkingTreeTestProviderAdapter,
44
                                _legacy_formats,
45
                                )
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
46
from bzrlib.workingtree_4 import (
47
    DirStateRevisionTree,
48
    WorkingTreeFormat4,
49
    )
1852.6.1 by Robert Collins
Start tree implementation tests.
50
51
52
def return_parameter(something):
53
    """A trivial thunk to return its input."""
54
    return something
55
56
57
def revision_tree_from_workingtree(tree):
58
    """Create a revision tree from a working tree."""
59
    revid = tree.commit('save tree', allow_pointless=True)
60
    return tree.branch.repository.revision_tree(revid)
61
62
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
63
def _dirstate_tree_from_workingtree(tree):
64
    revid = tree.commit('save tree', allow_pointless=True)
65
    return tree.basis_tree()
66
67
1852.6.1 by Robert Collins
Start tree implementation tests.
68
class TestTreeImplementationSupport(TestCaseWithTransport):
69
70
    def test_revision_tree_from_workingtree(self):
71
        tree = self.make_branch_and_tree('.')
72
        tree = revision_tree_from_workingtree(tree)
73
        self.assertIsInstance(tree, RevisionTree)
74
75
76
class TestCaseWithTree(TestCaseWithBzrDir):
77
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
78
    def make_branch_and_tree(self, relpath):
79
        made_control = self.make_bzrdir(relpath, format=
80
            self.workingtree_format._matchingbzrdir)
1852.6.1 by Robert Collins
Start tree implementation tests.
81
        made_control.create_repository()
82
        made_control.create_branch()
83
        return self.workingtree_format.initialize(made_control)
84
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
85
    def _convert_tree(self, tree, converter=None):
86
        """helper to convert using the converter or a supplied one."""
87
        # convert that to the final shape
88
        if converter is None:
89
            converter = self.workingtree_to_test_tree
90
        return converter(tree)
91
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
92
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
93
        """Make a tree with no parents and no contents from empty_tree.
94
        
95
        :param empty_tree: A working tree with no content and no parents to
96
            modify.
97
        """
1731.1.33 by Aaron Bentley
Revert no-special-root changes
98
        empty_tree.set_root_id('empty-root-id')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
99
        return self._convert_tree(empty_tree, converter)
1852.6.1 by Robert Collins
Start tree implementation tests.
100
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
101
    def _make_abc_tree(self, tree):
102
        """setup an abc content tree."""
103
        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.
104
        self.build_tree(files, line_endings='binary',
1982.1.4 by Alexander Belchenko
tree_implementations tests: build_tree with binary (LF) line-endings
105
                        transport=tree.bzrdir.root_transport)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
106
        tree.set_root_id('root-id')
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
107
        tree.add(files, ['a-id', 'b-id', 'c-id'])
108
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
109
    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.
110
        """return a test tree with a, b/, b/c contents."""
111
        self._make_abc_tree(tree)
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
112
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
113
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
114
    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.
115
        """return a test tree with a, b/, b/c contents.
116
        
117
        This variation changes the content of 'a' to foobar\n.
118
        """
119
        self._make_abc_tree(tree)
120
        f = open(tree.basedir + '/a', 'wb')
121
        try:
122
            f.write('foobar\n')
123
        finally:
124
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
125
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
126
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
127
    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.
128
        """return a test tree with a, b/, b/c contents.
129
        
130
        This variation changes the executable flag of b/c to True.
131
        """
132
        self._make_abc_tree(tree)
133
        tt = transform.TreeTransform(tree)
134
        trans_id = tt.trans_id_tree_path('b/c')
135
        tt.set_executability(True, trans_id)
136
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
137
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
138
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
139
    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.
140
        """return a test tree with d, b/, b/c contents.
141
        
142
        This variation renames a to d.
143
        """
144
        self._make_abc_tree(tree)
145
        tree.rename_one('a', 'd')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
146
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
147
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
148
    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.
149
        """return a test tree with d, b/, b/c contents.
150
        
151
        This variation renames a to d and alters its content to 'bar\n'.
152
        """
153
        self._make_abc_tree(tree)
154
        tree.rename_one('a', 'd')
155
        f = open(tree.basedir + '/d', 'wb')
156
        try:
157
            f.write('bar\n')
158
        finally:
159
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
160
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
161
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
162
    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.
163
        """return a test tree with a, b/, e contents.
164
        
165
        This variation renames b/c to e, and makes it executable.
166
        """
167
        self._make_abc_tree(tree)
168
        tt = transform.TreeTransform(tree)
169
        trans_id = tt.trans_id_tree_path('b/c')
170
        parent_trans_id = tt.trans_id_tree_path('')
171
        tt.adjust_path('e', parent_trans_id, trans_id)
172
        tt.set_executability(True, trans_id)
173
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
174
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
175
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
176
    def get_tree_with_subdirs_and_all_content_types(self):
177
        """Return a test tree with subdirs and all content types.
178
179
        The returned tree has the following inventory:
180
            [('', inventory.ROOT_ID),
181
             ('0file', '2file'),
182
             ('1top-dir', '1top-dir'),
183
             (u'2utf\u1234file', u'0utf\u1234file'),
184
             ('symlink', 'symlink'),
185
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
186
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
187
        where each component has the type of its name - i.e. '1file..' is afile.
188
189
        note that the order of the paths and fileids is deliberately 
190
        mismatched to ensure that the result order is path based.
191
        """
192
        tree = self.make_branch_and_tree('.')
193
        paths = ['0file',
194
            '1top-dir/',
195
            u'2utf\u1234file',
196
            '1top-dir/0file-in-1topdir',
197
            '1top-dir/1dir-in-1topdir/'
198
            ]
199
        ids = [
200
            '2file',
201
            '1top-dir',
202
            u'0utf\u1234file',
203
            '1file-in-1topdir',
204
            '0dir-in-1topdir'
205
            ]
206
        self.build_tree(paths)
207
        tree.add(paths, ids)
208
        tt = transform.TreeTransform(tree)
209
        root_transaction_id = tt.trans_id_tree_path('')
210
        tt.new_symlink('symlink',
211
            root_transaction_id, 'link-target', 'symlink')
212
        tt.apply()
213
        return self.workingtree_to_test_tree(tree)
214
1852.6.1 by Robert Collins
Start tree implementation tests.
215
216
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
217
    """Generate test suites for each Tree implementation in bzrlib.
218
219
    Currently this covers all working tree formats, and RevisionTree by 
220
    committing a working tree to create the revision tree.
221
    """
222
223
    def adapt(self, test):
224
        result = super(TreeTestProviderAdapter, self).adapt(test)
225
        for adapted_test in result:
226
            # for working tree adapted tests, preserve the tree
227
            adapted_test.workingtree_to_test_tree = return_parameter
228
        default_format = WorkingTreeFormat.get_default_format()
229
        revision_tree_test = self._clone_test(
230
            test,
231
            default_format._matchingbzrdir, 
232
            default_format,
233
            RevisionTree.__name__)
234
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
235
        result.addTest(revision_tree_test)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
236
        dirstate_format = WorkingTreeFormat4()
237
        dirstate_revision_tree_test = self._clone_test(
238
            test,
239
            dirstate_format._matchingbzrdir,
240
            dirstate_format,
241
            DirStateRevisionTree.__name__)
242
        dirstate_revision_tree_test.workingtree_to_test_tree = _dirstate_tree_from_workingtree
243
        result.addTest(dirstate_revision_tree_test)
1852.6.1 by Robert Collins
Start tree implementation tests.
244
        return result
245
246
247
def test_suite():
248
    result = TestSuite()
249
    test_tree_implementations = [
2255.2.71 by John Arbash Meinel
Add a test for list_files, and implement it for DirStateRevisionTree
250
        'bzrlib.tests.tree_implementations.test_list_files',
1908.11.5 by John Arbash Meinel
[merge] bzr.dev 2240
251
        'bzrlib.tests.tree_implementations.test_revision_tree',
1852.6.1 by Robert Collins
Start tree implementation tests.
252
        'bzrlib.tests.tree_implementations.test_test_trees',
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
253
        'bzrlib.tests.tree_implementations.test_tree',
1852.15.3 by Robert Collins
Add a first-cut Tree.walkdirs method.
254
        'bzrlib.tests.tree_implementations.test_walkdirs',
1852.6.1 by Robert Collins
Start tree implementation tests.
255
        ]
256
    adapter = TreeTestProviderAdapter(
257
        default_transport,
258
        # None here will cause a readonly decorator to be created
259
        # by the TestCaseWithTransport.get_readonly_transport method.
260
        None,
261
        [(format, format._matchingbzrdir) for format in 
262
         WorkingTreeFormat._formats.values() + _legacy_formats])
263
    loader = TestLoader()
264
    adapt_modules(test_tree_implementations, adapter, loader, result)
265
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))
266
    return result