~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from 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
24
24
    def test_empty_tree_no_parents(self):
25
25
        tree = self.make_branch_and_tree('.')
26
26
        tree = self.get_tree_no_parents_no_content(tree)
 
27
        tree.lock_read()
 
28
        self.addCleanup(tree.unlock)
27
29
        self.assertEqual([], tree.get_parent_ids())
28
30
        self.assertEqual([], tree.conflicts())
29
31
        self.assertEqual([], list(tree.unknowns()))
35
37
    def test_abc_tree_no_parents(self):
36
38
        tree = self.make_branch_and_tree('.')
37
39
        tree = self.get_tree_no_parents_abc_content(tree)
 
40
        tree.lock_read()
 
41
        self.addCleanup(tree.unlock)
38
42
        self.assertEqual([], tree.get_parent_ids())
39
43
        self.assertEqual([], tree.conflicts())
40
44
        self.assertEqual([], list(tree.unknowns()))
51
55
    def test_abc_tree_content_2_no_parents(self):
52
56
        tree = self.make_branch_and_tree('.')
53
57
        tree = self.get_tree_no_parents_abc_content_2(tree)
 
58
        tree.lock_read()
 
59
        self.addCleanup(tree.unlock)
54
60
        self.assertEqual([], tree.get_parent_ids())
55
61
        self.assertEqual([], tree.conflicts())
56
62
        self.assertEqual([], list(tree.unknowns()))
63
69
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
64
70
        self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
65
71
        self.assertFalse(tree.is_executable('c-id'))
66
 
        
 
72
 
67
73
    def test_abc_tree_content_3_no_parents(self):
68
74
        tree = self.make_branch_and_tree('.')
69
75
        tree = self.get_tree_no_parents_abc_content_3(tree)
 
76
        tree.lock_read()
 
77
        self.addCleanup(tree.unlock)
70
78
        self.assertEqual([], tree.get_parent_ids())
71
79
        self.assertEqual([], tree.conflicts())
72
80
        self.assertEqual([], list(tree.unknowns()))
79
87
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
80
88
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
81
89
        self.assertTrue(tree.is_executable('c-id'))
82
 
        
 
90
 
83
91
    def test_abc_tree_content_4_no_parents(self):
84
92
        tree = self.make_branch_and_tree('.')
85
93
        tree = self.get_tree_no_parents_abc_content_4(tree)
 
94
        tree.lock_read()
 
95
        self.addCleanup(tree.unlock)
86
96
        self.assertEqual([], tree.get_parent_ids())
87
97
        self.assertEqual([], tree.conflicts())
88
98
        self.assertEqual([], list(tree.unknowns()))
95
105
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
96
106
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
97
107
        self.assertFalse(tree.is_executable('c-id'))
98
 
        
 
108
 
99
109
    def test_abc_tree_content_5_no_parents(self):
100
110
        tree = self.make_branch_and_tree('.')
101
111
        tree = self.get_tree_no_parents_abc_content_5(tree)
 
112
        tree.lock_read()
 
113
        self.addCleanup(tree.unlock)
102
114
        self.assertEqual([], tree.get_parent_ids())
103
115
        self.assertEqual([], tree.conflicts())
104
116
        self.assertEqual([], list(tree.unknowns()))
111
123
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
112
124
        self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
113
125
        self.assertFalse(tree.is_executable('c-id'))
114
 
        
 
126
 
115
127
    def test_abc_tree_content_6_no_parents(self):
116
128
        tree = self.make_branch_and_tree('.')
117
129
        tree = self.get_tree_no_parents_abc_content_6(tree)
 
130
        tree.lock_read()
 
131
        self.addCleanup(tree.unlock)
118
132
        self.assertEqual([], tree.get_parent_ids())
119
133
        self.assertEqual([], tree.conflicts())
120
134
        self.assertEqual([], list(tree.unknowns()))
127
141
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
128
142
        self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
129
143
        self.assertTrue(tree.is_executable('c-id'))
 
144
 
 
145
    def test_tree_with_subdirs_and_all_content_types(self):
 
146
        # currently this test tree requires unicode. It might be good
 
147
        # to have it simply stop having the single unicode file in it
 
148
        # when dealing with a non-unicode filesystem.
 
149
        tree = self.get_tree_with_subdirs_and_all_content_types()
 
150
        tree.lock_read()
 
151
        self.addCleanup(tree.unlock)
 
152
        self.assertEqual([], tree.get_parent_ids())
 
153
        self.assertEqual([], tree.conflicts())
 
154
        self.assertEqual([], list(tree.unknowns()))
 
155
        # __iter__ has no strongly defined order
 
156
        tree_root = tree.path2id('')
 
157
        self.assertEqual(
 
158
            set([tree_root,
 
159
                '2file',
 
160
                '1top-dir',
 
161
                '1file-in-1topdir',
 
162
                '0dir-in-1topdir',
 
163
                 u'0utf\u1234file'.encode('utf8'),
 
164
                'symlink',
 
165
                 ]),
 
166
            set(iter(tree)))
 
167
        # note that the order of the paths and fileids is deliberately 
 
168
        # mismatched to ensure that the result order is path based.
 
169
        self.assertEqual(
 
170
            [('', tree_root, 'directory'),
 
171
             ('0file', '2file', 'file'),
 
172
             ('1top-dir', '1top-dir', 'directory'),
 
173
             (u'2utf\u1234file', u'0utf\u1234file'.encode('utf8'), 'file'),
 
174
             ('symlink', 'symlink', 'symlink'),
 
175
             ('1top-dir/0file-in-1topdir', '1file-in-1topdir', 'file'),
 
176
             ('1top-dir/1dir-in-1topdir', '0dir-in-1topdir', 'directory')],
 
177
            [(path, node.file_id, node.kind) for path, node in tree.iter_entries_by_dir()])
 
178
 
 
179
    def test_tree_with_utf8(self):
 
180
        tree = self.make_branch_and_tree('.')
 
181
        tree = self.get_tree_with_utf8(tree)
 
182
 
 
183
        revision_id = u'r\xe9v-1'.encode('utf8')
 
184
        root_id = 'TREE_ROOT'
 
185
        bar_id = u'b\xe5r-id'.encode('utf8')
 
186
        foo_id = u'f\xf6-id'.encode('utf8')
 
187
        baz_id = u'b\xe1z-id'.encode('utf8')
 
188
        path_and_ids = [(u'', root_id, None),
 
189
                        (u'b\xe5r', bar_id, root_id),
 
190
                        (u'f\xf6', foo_id, root_id),
 
191
                        (u'b\xe5r/b\xe1z', baz_id, bar_id),
 
192
                       ]
 
193
        tree.lock_read()
 
194
        try:
 
195
            path_entries = list(tree.iter_entries_by_dir())
 
196
        finally:
 
197
            tree.unlock()
 
198
 
 
199
        for expected, (path, ie) in zip(path_and_ids, path_entries):
 
200
            self.assertEqual(expected[0], path) # Paths should match
 
201
            self.assertIsInstance(path, unicode)
 
202
            self.assertEqual(expected[1], ie.file_id)
 
203
            self.assertIsInstance(ie.file_id, str)
 
204
            self.assertEqual(expected[2], ie.parent_id)
 
205
            if expected[2] is not None:
 
206
                self.assertIsInstance(ie.parent_id, str)
 
207
            # WorkingTree's return None for the last modified revision
 
208
            if ie.revision is not None:
 
209
                self.assertIsInstance(ie.revision, str)
 
210
                if expected[0] != '':
 
211
                    # Some trees will preserve the revision id of the tree root,
 
212
                    # but not all will
 
213
                    self.assertEqual(revision_id, ie.revision)
 
214
        self.assertEqual(len(path_and_ids), len(path_entries))
 
215
        get_revision_id = getattr(tree, 'get_revision_id', None)
 
216
        if get_revision_id is not None:
 
217
            self.assertIsInstance(get_revision_id(), str)
 
218
        last_revision = getattr(tree, 'last_revision', None)
 
219
        if last_revision is not None:
 
220
            self.assertIsInstance(last_revision(), str)
 
221
 
 
222
    def test_tree_with_merged_utf8(self):
 
223
        tree = self.make_branch_and_tree('.')
 
224
        tree = self.get_tree_with_merged_utf8(tree)
 
225
 
 
226
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
 
227
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
 
228
        root_id = 'TREE_ROOT'
 
229
        bar_id = u'b\xe5r-id'.encode('utf8')
 
230
        foo_id = u'f\xf6-id'.encode('utf8')
 
231
        baz_id = u'b\xe1z-id'.encode('utf8')
 
232
        zez_id = u'z\xf7z-id'.encode('utf8')
 
233
        path_and_ids = [(u'', root_id, None, None),
 
234
                        (u'b\xe5r', bar_id, root_id, revision_id_1),
 
235
                        (u'f\xf6', foo_id, root_id, revision_id_1),
 
236
                        (u'b\xe5r/b\xe1z', baz_id, bar_id, revision_id_1),
 
237
                        (u'b\xe5r/z\xf7z', zez_id, bar_id, revision_id_2),
 
238
                       ]
 
239
        tree.lock_read()
 
240
        try:
 
241
            path_entries = list(tree.iter_entries_by_dir())
 
242
        finally:
 
243
            tree.unlock()
 
244
 
 
245
        for expected, (path, ie) in zip(path_and_ids, path_entries):
 
246
            self.assertEqual(expected[0], path) # Paths should match
 
247
            self.assertIsInstance(path, unicode)
 
248
            self.assertEqual(expected[1], ie.file_id)
 
249
            self.assertIsInstance(ie.file_id, str)
 
250
            self.assertEqual(expected[2], ie.parent_id)
 
251
            if expected[2] is not None:
 
252
                self.assertIsInstance(ie.parent_id, str)
 
253
            # WorkingTree's return None for the last modified revision
 
254
            if ie.revision is not None:
 
255
                self.assertIsInstance(ie.revision, str)
 
256
                if expected[0] == '':
 
257
                    # Some trees will preserve the revision id of the tree root,
 
258
                    # but not all will
 
259
                    continue
 
260
                self.assertEqual(expected[3], ie.revision)
 
261
        self.assertEqual(len(path_and_ids), len(path_entries))
 
262
        get_revision_id = getattr(tree, 'get_revision_id', None)
 
263
        if get_revision_id is not None:
 
264
            self.assertIsInstance(get_revision_id(), str)
 
265
        last_revision = getattr(tree, 'last_revision', None)
 
266
        if last_revision is not None:
 
267
            self.assertIsInstance(last_revision(), str)