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