/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

  • Committer: Robert Collins
  • Date: 2008-08-20 02:07:36 UTC
  • mfrom: (3640 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820020736-g2xe4921zzxtymle
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

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