/brz/remove-bazaar

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