/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/test_test_trees.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for the test trees used by the tree_implementations tests."""
18
18
 
 
19
from bzrlib.osutils import has_symlinks
 
20
from bzrlib.tests import TestSkipped
19
21
from bzrlib.tests.tree_implementations import TestCaseWithTree
20
22
 
21
23
 
24
26
    def test_empty_tree_no_parents(self):
25
27
        tree = self.make_branch_and_tree('.')
26
28
        tree = self.get_tree_no_parents_no_content(tree)
 
29
        tree.lock_read()
 
30
        self.addCleanup(tree.unlock)
27
31
        self.assertEqual([], tree.get_parent_ids())
28
32
        self.assertEqual([], tree.conflicts())
29
33
        self.assertEqual([], list(tree.unknowns()))
35
39
    def test_abc_tree_no_parents(self):
36
40
        tree = self.make_branch_and_tree('.')
37
41
        tree = self.get_tree_no_parents_abc_content(tree)
 
42
        tree.lock_read()
 
43
        self.addCleanup(tree.unlock)
38
44
        self.assertEqual([], tree.get_parent_ids())
39
45
        self.assertEqual([], tree.conflicts())
40
46
        self.assertEqual([], list(tree.unknowns()))
51
57
    def test_abc_tree_content_2_no_parents(self):
52
58
        tree = self.make_branch_and_tree('.')
53
59
        tree = self.get_tree_no_parents_abc_content_2(tree)
 
60
        tree.lock_read()
 
61
        self.addCleanup(tree.unlock)
54
62
        self.assertEqual([], tree.get_parent_ids())
55
63
        self.assertEqual([], tree.conflicts())
56
64
        self.assertEqual([], list(tree.unknowns()))
63
71
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
64
72
        self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
65
73
        self.assertFalse(tree.is_executable('c-id'))
66
 
        
 
74
 
67
75
    def test_abc_tree_content_3_no_parents(self):
68
76
        tree = self.make_branch_and_tree('.')
69
77
        tree = self.get_tree_no_parents_abc_content_3(tree)
 
78
        tree.lock_read()
 
79
        self.addCleanup(tree.unlock)
70
80
        self.assertEqual([], tree.get_parent_ids())
71
81
        self.assertEqual([], tree.conflicts())
72
82
        self.assertEqual([], list(tree.unknowns()))
79
89
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
80
90
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
81
91
        self.assertTrue(tree.is_executable('c-id'))
82
 
        
 
92
 
83
93
    def test_abc_tree_content_4_no_parents(self):
84
94
        tree = self.make_branch_and_tree('.')
85
95
        tree = self.get_tree_no_parents_abc_content_4(tree)
 
96
        tree.lock_read()
 
97
        self.addCleanup(tree.unlock)
86
98
        self.assertEqual([], tree.get_parent_ids())
87
99
        self.assertEqual([], tree.conflicts())
88
100
        self.assertEqual([], list(tree.unknowns()))
95
107
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
96
108
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
97
109
        self.assertFalse(tree.is_executable('c-id'))
98
 
        
 
110
 
99
111
    def test_abc_tree_content_5_no_parents(self):
100
112
        tree = self.make_branch_and_tree('.')
101
113
        tree = self.get_tree_no_parents_abc_content_5(tree)
 
114
        tree.lock_read()
 
115
        self.addCleanup(tree.unlock)
102
116
        self.assertEqual([], tree.get_parent_ids())
103
117
        self.assertEqual([], tree.conflicts())
104
118
        self.assertEqual([], list(tree.unknowns()))
111
125
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
112
126
        self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
113
127
        self.assertFalse(tree.is_executable('c-id'))
114
 
        
 
128
 
115
129
    def test_abc_tree_content_6_no_parents(self):
116
130
        tree = self.make_branch_and_tree('.')
117
131
        tree = self.get_tree_no_parents_abc_content_6(tree)
 
132
        tree.lock_read()
 
133
        self.addCleanup(tree.unlock)
118
134
        self.assertEqual([], tree.get_parent_ids())
119
135
        self.assertEqual([], tree.conflicts())
120
136
        self.assertEqual([], list(tree.unknowns()))
127
143
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
128
144
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
129
145
        self.assertTrue(tree.is_executable('c-id'))
 
146
 
 
147
    def test_tree_with_subdirs_and_all_content_types(self):
 
148
        # currently this test tree requires unicode. It might be good
 
149
        # to have it simply stop having the single unicode file in it
 
150
        # when dealing with a non-unicode filesystem.
 
151
        if not has_symlinks():
 
152
            raise TestSkipped('No symlink support')
 
153
        tree = self.get_tree_with_subdirs_and_all_content_types()
 
154
        tree.lock_read()
 
155
        self.addCleanup(tree.unlock)
 
156
        self.assertEqual([], tree.get_parent_ids())
 
157
        self.assertEqual([], tree.conflicts())
 
158
        self.assertEqual([], list(tree.unknowns()))
 
159
        # __iter__ has no strongly defined order
 
160
        tree_root = tree.path2id('')
 
161
        self.assertEqual(
 
162
            set([tree_root,
 
163
                '2file',
 
164
                '1top-dir',
 
165
                '1file-in-1topdir',
 
166
                '0dir-in-1topdir',
 
167
                 u'0utf\u1234file'.encode('utf8'),
 
168
                'symlink',
 
169
                 ]),
 
170
            set(iter(tree)))
 
171
        # note that the order of the paths and fileids is deliberately 
 
172
        # mismatched to ensure that the result order is path based.
 
173
        self.assertEqual(
 
174
            [('', tree_root, 'directory'),
 
175
             ('0file', '2file', 'file'),
 
176
             ('1top-dir', '1top-dir', 'directory'),
 
177
             (u'2utf\u1234file', u'0utf\u1234file'.encode('utf8'), 'file'),
 
178
             ('symlink', 'symlink', 'symlink'),
 
179
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir', 'file'),
 
180
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir', 'directory')],
 
181
            [(path, node.file_id, node.kind) for path, node in tree.iter_entries_by_dir()])
 
182
 
 
183
    def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
 
184
        # currently this test tree requires unicode. It might be good
 
185
        # to have it simply stop having the single unicode file in it
 
186
        # when dealing with a non-unicode filesystem.
 
187
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(False)
 
188
        tree.lock_read()
 
189
        self.addCleanup(tree.unlock)
 
190
        self.assertEqual([], tree.get_parent_ids())
 
191
        self.assertEqual([], tree.conflicts())
 
192
        self.assertEqual([], list(tree.unknowns()))
 
193
        # __iter__ has no strongly defined order
 
194
        tree_root = tree.path2id('')
 
195
        self.assertEqual(
 
196
            set([tree_root,
 
197
                '2file',
 
198
                '1top-dir',
 
199
                '1file-in-1topdir',
 
200
                '0dir-in-1topdir',
 
201
                 u'0utf\u1234file'.encode('utf8'),
 
202
                 ]),
 
203
            set(iter(tree)))
 
204
        # note that the order of the paths and fileids is deliberately 
 
205
        # mismatched to ensure that the result order is path based.
 
206
        self.assertEqual(
 
207
            [('', tree_root, 'directory'),
 
208
             ('0file', '2file', 'file'),
 
209
             ('1top-dir', '1top-dir', 'directory'),
 
210
             (u'2utf\u1234file', u'0utf\u1234file'.encode('utf8'), 'file'),
 
211
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir', 'file'),
 
212
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir', 'directory')],
 
213
            [(path, node.file_id, node.kind) for path, node in tree.iter_entries_by_dir()])
 
214
 
 
215
    def test_tree_with_utf8(self):
 
216
        tree = self.make_branch_and_tree('.')
 
217
        tree = self.get_tree_with_utf8(tree)
 
218
 
 
219
        revision_id = u'r\xe9v-1'.encode('utf8')
 
220
        root_id = 'TREE_ROOT'
 
221
        bar_id = u'b\xe5r-id'.encode('utf8')
 
222
        foo_id = u'f\xf6-id'.encode('utf8')
 
223
        baz_id = u'b\xe1z-id'.encode('utf8')
 
224
        path_and_ids = [(u'', root_id, None),
 
225
                        (u'b\xe5r', bar_id, root_id),
 
226
                        (u'f\xf6', foo_id, root_id),
 
227
                        (u'b\xe5r/b\xe1z', baz_id, bar_id),
 
228
                       ]
 
229
        tree.lock_read()
 
230
        try:
 
231
            path_entries = list(tree.iter_entries_by_dir())
 
232
        finally:
 
233
            tree.unlock()
 
234
 
 
235
        for expected, (path, ie) in zip(path_and_ids, path_entries):
 
236
            self.assertEqual(expected[0], path) # Paths should match
 
237
            self.assertIsInstance(path, unicode)
 
238
            self.assertEqual(expected[1], ie.file_id)
 
239
            self.assertIsInstance(ie.file_id, str)
 
240
            self.assertEqual(expected[2], ie.parent_id)
 
241
            if expected[2] is not None:
 
242
                self.assertIsInstance(ie.parent_id, str)
 
243
            # WorkingTree's return None for the last modified revision
 
244
            if ie.revision is not None:
 
245
                self.assertIsInstance(ie.revision, str)
 
246
                if expected[0] != '':
 
247
                    # Some trees will preserve the revision id of the tree root,
 
248
                    # but not all will
 
249
                    self.assertEqual(revision_id, ie.revision)
 
250
        self.assertEqual(len(path_and_ids), len(path_entries))
 
251
        get_revision_id = getattr(tree, 'get_revision_id', None)
 
252
        if get_revision_id is not None:
 
253
            self.assertIsInstance(get_revision_id(), str)
 
254
        last_revision = getattr(tree, 'last_revision', None)
 
255
        if last_revision is not None:
 
256
            self.assertIsInstance(last_revision(), str)
 
257
 
 
258
    def test_tree_with_merged_utf8(self):
 
259
        tree = self.make_branch_and_tree('.')
 
260
        tree = self.get_tree_with_merged_utf8(tree)
 
261
 
 
262
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
 
263
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
 
264
        root_id = 'TREE_ROOT'
 
265
        bar_id = u'b\xe5r-id'.encode('utf8')
 
266
        foo_id = u'f\xf6-id'.encode('utf8')
 
267
        baz_id = u'b\xe1z-id'.encode('utf8')
 
268
        zez_id = u'z\xf7z-id'.encode('utf8')
 
269
        path_and_ids = [(u'', root_id, None, None),
 
270
                        (u'b\xe5r', bar_id, root_id, revision_id_1),
 
271
                        (u'f\xf6', foo_id, root_id, revision_id_1),
 
272
                        (u'b\xe5r/b\xe1z', baz_id, bar_id, revision_id_1),
 
273
                        (u'b\xe5r/z\xf7z', zez_id, bar_id, revision_id_2),
 
274
                       ]
 
275
        tree.lock_read()
 
276
        try:
 
277
            path_entries = list(tree.iter_entries_by_dir())
 
278
        finally:
 
279
            tree.unlock()
 
280
 
 
281
        for expected, (path, ie) in zip(path_and_ids, path_entries):
 
282
            self.assertEqual(expected[0], path) # Paths should match
 
283
            self.assertIsInstance(path, unicode)
 
284
            self.assertEqual(expected[1], ie.file_id)
 
285
            self.assertIsInstance(ie.file_id, str)
 
286
            self.assertEqual(expected[2], ie.parent_id)
 
287
            if expected[2] is not None:
 
288
                self.assertIsInstance(ie.parent_id, str)
 
289
            # WorkingTree's return None for the last modified revision
 
290
            if ie.revision is not None:
 
291
                self.assertIsInstance(ie.revision, str)
 
292
                if expected[0] == '':
 
293
                    # Some trees will preserve the revision id of the tree root,
 
294
                    # but not all will
 
295
                    continue
 
296
                self.assertEqual(expected[3], ie.revision)
 
297
        self.assertEqual(len(path_and_ids), len(path_entries))
 
298
        get_revision_id = getattr(tree, 'get_revision_id', None)
 
299
        if get_revision_id is not None:
 
300
            self.assertIsInstance(get_revision_id(), str)
 
301
        last_revision = getattr(tree, 'last_revision', None)
 
302
        if last_revision is not None:
 
303
            self.assertIsInstance(last_revision(), str)