/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,
2309.4.10 by John Arbash Meinel
(fixed) Fix the last few tests that were explicitly passing around unicode ids
30
    osutils,
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
31
    tests,
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
32
    transform,
33
    )
1852.6.1 by Robert Collins
Start tree implementation tests.
34
from bzrlib.transport import get_transport
35
from bzrlib.tests import (
36
                          adapt_modules,
37
                          default_transport,
38
                          TestCaseWithTransport,
39
                          TestLoader,
40
                          TestSuite,
41
                          )
42
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()
43
from bzrlib.revisiontree import RevisionTree
1852.6.1 by Robert Collins
Start tree implementation tests.
44
from bzrlib.workingtree import (WorkingTreeFormat,
45
                                WorkingTreeTestProviderAdapter,
46
                                _legacy_formats,
47
                                )
48
49
50
def return_parameter(something):
51
    """A trivial thunk to return its input."""
52
    return something
53
54
55
def revision_tree_from_workingtree(tree):
56
    """Create a revision tree from a working tree."""
57
    revid = tree.commit('save tree', allow_pointless=True)
58
    return tree.branch.repository.revision_tree(revid)
59
60
61
class TestTreeImplementationSupport(TestCaseWithTransport):
62
63
    def test_revision_tree_from_workingtree(self):
64
        tree = self.make_branch_and_tree('.')
65
        tree = revision_tree_from_workingtree(tree)
66
        self.assertIsInstance(tree, RevisionTree)
67
68
69
class TestCaseWithTree(TestCaseWithBzrDir):
70
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
71
    def make_branch_and_tree(self, relpath):
72
        made_control = self.make_bzrdir(relpath, format=
73
            self.workingtree_format._matchingbzrdir)
1852.6.1 by Robert Collins
Start tree implementation tests.
74
        made_control.create_repository()
75
        made_control.create_branch()
76
        return self.workingtree_format.initialize(made_control)
77
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
78
    def _convert_tree(self, tree, converter=None):
79
        """helper to convert using the converter or a supplied one."""
80
        # convert that to the final shape
81
        if converter is None:
82
            converter = self.workingtree_to_test_tree
83
        return converter(tree)
84
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
85
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
86
        """Make a tree with no parents and no contents from empty_tree.
87
        
88
        :param empty_tree: A working tree with no content and no parents to
89
            modify.
90
        """
1731.1.33 by Aaron Bentley
Revert no-special-root changes
91
        empty_tree.set_root_id('empty-root-id')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
92
        return self._convert_tree(empty_tree, converter)
1852.6.1 by Robert Collins
Start tree implementation tests.
93
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
94
    def _make_abc_tree(self, tree):
95
        """setup an abc content tree."""
96
        files = ['a', 'b/', 'b/c']
1731.1.48 by Aaron Bentley
Merge from bzr.dev
97
        self.build_tree(files, line_endings='binary', 
1982.1.4 by Alexander Belchenko
tree_implementations tests: build_tree with binary (LF) line-endings
98
                        transport=tree.bzrdir.root_transport)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
99
        tree.set_root_id('root-id')
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
100
        tree.add(files, ['a-id', 'b-id', 'c-id'])
101
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
102
    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.
103
        """return a test tree with a, b/, b/c contents."""
104
        self._make_abc_tree(tree)
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
105
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
106
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
107
    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.
108
        """return a test tree with a, b/, b/c contents.
109
        
110
        This variation changes the content of 'a' to foobar\n.
111
        """
112
        self._make_abc_tree(tree)
113
        f = open(tree.basedir + '/a', 'wb')
114
        try:
115
            f.write('foobar\n')
116
        finally:
117
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
118
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
119
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
120
    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.
121
        """return a test tree with a, b/, b/c contents.
122
        
123
        This variation changes the executable flag of b/c to True.
124
        """
125
        self._make_abc_tree(tree)
126
        tt = transform.TreeTransform(tree)
127
        trans_id = tt.trans_id_tree_path('b/c')
128
        tt.set_executability(True, trans_id)
129
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
130
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
131
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
132
    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.
133
        """return a test tree with d, b/, b/c contents.
134
        
135
        This variation renames a to d.
136
        """
137
        self._make_abc_tree(tree)
138
        tree.rename_one('a', 'd')
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
139
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
140
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
141
    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.
142
        """return a test tree with d, b/, b/c contents.
143
        
144
        This variation renames a to d and alters its content to 'bar\n'.
145
        """
146
        self._make_abc_tree(tree)
147
        tree.rename_one('a', 'd')
148
        f = open(tree.basedir + '/d', 'wb')
149
        try:
150
            f.write('bar\n')
151
        finally:
152
            f.close()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
153
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
154
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
155
    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.
156
        """return a test tree with a, b/, e contents.
157
        
158
        This variation renames b/c to e, and makes it executable.
159
        """
160
        self._make_abc_tree(tree)
161
        tt = transform.TreeTransform(tree)
162
        trans_id = tt.trans_id_tree_path('b/c')
163
        parent_trans_id = tt.trans_id_tree_path('')
164
        tt.adjust_path('e', parent_trans_id, trans_id)
165
        tt.set_executability(True, trans_id)
166
        tt.apply()
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
167
        return self._convert_tree(tree, converter)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
168
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
169
    def get_tree_with_utf8(self, tree):
170
        """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
171
        self._create_tree_with_utf8(tree)
172
        return self.workingtree_to_test_tree(tree)
173
174
    def _create_tree_with_utf8(self, tree):
175
        """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.
176
        paths = [u'',
177
                 u'f\xf6',
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
178
                 u'b\xe5r/',
179
                 u'b\xe5r/b\xe1z',
180
                ]
181
        # bzr itself does not create unicode file ids, but we want them for
182
        # testing.
2309.4.10 by John Arbash Meinel
(fixed) Fix the last few tests that were explicitly passing around unicode ids
183
        file_ids = ['TREE_ROOT',
184
                    'f\xc3\xb6-id',
185
                    'b\xc3\xa5r-id',
186
                    'b\xc3\xa1z-id',
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
187
                   ]
188
        try:
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
189
            self.build_tree(paths[1:])
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
190
        except UnicodeError:
191
            raise tests.TestSkipped('filesystem does not support unicode.')
192
        tree.add(paths, file_ids)
193
        try:
194
            tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
195
        except errors.NonAsciiRevisionId:
196
            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
197
198
    def get_tree_with_merged_utf8(self, tree):
199
        """Generate a tree with utf8 ancestors."""
200
        self._create_tree_with_utf8(tree)
201
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
202
        self.build_tree([u'tree2/b\xe5r/z\xf7z'])
2309.4.10 by John Arbash Meinel
(fixed) Fix the last few tests that were explicitly passing around unicode ids
203
        self.callDeprecated([osutils._file_id_warning],
204
                            tree2.add, [u'b\xe5r/z\xf7z'], [u'z\xf7z-id'])
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
205
        tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
206
207
        tree.merge_from_branch(tree2.branch)
208
        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.
209
        return self.workingtree_to_test_tree(tree)
210
1852.6.1 by Robert Collins
Start tree implementation tests.
211
212
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
213
    """Generate test suites for each Tree implementation in bzrlib.
214
215
    Currently this covers all working tree formats, and RevisionTree by 
216
    committing a working tree to create the revision tree.
217
    """
218
219
    def adapt(self, test):
220
        result = super(TreeTestProviderAdapter, self).adapt(test)
221
        for adapted_test in result:
222
            # for working tree adapted tests, preserve the tree
223
            adapted_test.workingtree_to_test_tree = return_parameter
224
        default_format = WorkingTreeFormat.get_default_format()
225
        revision_tree_test = self._clone_test(
226
            test,
227
            default_format._matchingbzrdir, 
228
            default_format,
229
            RevisionTree.__name__)
230
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
231
        result.addTest(revision_tree_test)
232
        return result
233
234
235
def test_suite():
236
    result = TestSuite()
237
    test_tree_implementations = [
238
        'bzrlib.tests.tree_implementations.test_test_trees',
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
239
        'bzrlib.tests.tree_implementations.test_tree',
1852.6.1 by Robert Collins
Start tree implementation tests.
240
        ]
241
    adapter = TreeTestProviderAdapter(
242
        default_transport,
243
        # None here will cause a readonly decorator to be created
244
        # by the TestCaseWithTransport.get_readonly_transport method.
245
        None,
246
        [(format, format._matchingbzrdir) for format in 
247
         WorkingTreeFormat._formats.values() + _legacy_formats])
248
    loader = TestLoader()
249
    adapt_modules(test_tree_implementations, adapter, loader, result)
250
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))
251
    return result