52
57
def test_abc_tree_content_2_no_parents(self):
53
58
tree = self.make_branch_and_tree('.')
54
59
tree = self.get_tree_no_parents_abc_content_2(tree)
61
self.addCleanup(tree.unlock)
55
62
self.assertEqual([], tree.get_parent_ids())
56
63
self.assertEqual([], tree.conflicts())
57
64
self.assertEqual([], list(tree.unknowns()))
58
65
# __iter__ has no strongly defined order
60
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
67
set(['root-id', 'a-id', 'b-id', 'c-id']),
63
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
70
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
64
71
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
65
72
self.assertEqualDiff('foobar\n', tree.get_file_text('a-id'))
66
73
self.assertFalse(tree.is_executable('c-id'))
68
75
def test_abc_tree_content_3_no_parents(self):
69
76
tree = self.make_branch_and_tree('.')
70
77
tree = self.get_tree_no_parents_abc_content_3(tree)
79
self.addCleanup(tree.unlock)
71
80
self.assertEqual([], tree.get_parent_ids())
72
81
self.assertEqual([], tree.conflicts())
73
82
self.assertEqual([], list(tree.unknowns()))
74
83
# __iter__ has no strongly defined order
76
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
85
set(['root-id', 'a-id', 'b-id', 'c-id']),
79
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
88
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')],
80
89
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
81
90
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
82
91
self.assertTrue(tree.is_executable('c-id'))
84
93
def test_abc_tree_content_4_no_parents(self):
85
94
tree = self.make_branch_and_tree('.')
86
95
tree = self.get_tree_no_parents_abc_content_4(tree)
97
self.addCleanup(tree.unlock)
87
98
self.assertEqual([], tree.get_parent_ids())
88
99
self.assertEqual([], tree.conflicts())
89
100
self.assertEqual([], list(tree.unknowns()))
90
101
# __iter__ has no strongly defined order
92
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
103
set(['root-id', 'a-id', 'b-id', 'c-id']),
95
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
106
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
96
107
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
97
108
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
98
109
self.assertFalse(tree.is_executable('c-id'))
100
111
def test_abc_tree_content_5_no_parents(self):
101
112
tree = self.make_branch_and_tree('.')
102
113
tree = self.get_tree_no_parents_abc_content_5(tree)
115
self.addCleanup(tree.unlock)
103
116
self.assertEqual([], tree.get_parent_ids())
104
117
self.assertEqual([], tree.conflicts())
105
118
self.assertEqual([], list(tree.unknowns()))
106
119
# __iter__ has no strongly defined order
107
120
self.assertEqual(
108
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
121
set(['root-id', 'a-id', 'b-id', 'c-id']),
110
123
self.assertEqual(
111
[('', inventory.ROOT_ID), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
124
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')],
112
125
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
113
126
self.assertEqualDiff('bar\n', tree.get_file_text('a-id'))
114
127
self.assertFalse(tree.is_executable('c-id'))
116
129
def test_abc_tree_content_6_no_parents(self):
117
130
tree = self.make_branch_and_tree('.')
118
131
tree = self.get_tree_no_parents_abc_content_6(tree)
133
self.addCleanup(tree.unlock)
119
134
self.assertEqual([], tree.get_parent_ids())
120
135
self.assertEqual([], tree.conflicts())
121
136
self.assertEqual([], list(tree.unknowns()))
122
137
# __iter__ has no strongly defined order
123
138
self.assertEqual(
124
set([inventory.ROOT_ID, 'a-id', 'b-id', 'c-id']),
139
set(['root-id', 'a-id', 'b-id', 'c-id']),
126
141
self.assertEqual(
127
[('', inventory.ROOT_ID), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
142
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')],
128
143
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
129
144
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
130
145
self.assertTrue(tree.is_executable('c-id'))
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()
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('')
167
u'0utf\u1234file'.encode('utf8'),
171
# note that the order of the paths and fileids is deliberately
172
# mismatched to ensure that the result order is path based.
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()])
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)
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('')
201
u'0utf\u1234file'.encode('utf8'),
204
# note that the order of the paths and fileids is deliberately
205
# mismatched to ensure that the result order is path based.
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()])
215
def test_tree_with_utf8(self):
216
tree = self.make_branch_and_tree('.')
217
tree = self.get_tree_with_utf8(tree)
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),
231
path_entries = list(tree.iter_entries_by_dir())
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,
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)
258
def test_tree_with_merged_utf8(self):
259
tree = self.make_branch_and_tree('.')
260
tree = self.get_tree_with_merged_utf8(tree)
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),
277
path_entries = list(tree.iter_entries_by_dir())
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,
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)