1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006, 2007 Canonical Ltd
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)
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)
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)
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'))
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)
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'))
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)
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'))
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)
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'))
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)
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()))
128
142
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id'))
129
143
self.assertTrue(tree.is_executable('c-id'))
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()
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('')
163
u'0utf\u1234file'.encode('utf8'),
167
# note that the order of the paths and fileids is deliberately
168
# mismatched to ensure that the result order is path based.
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()])
131
179
def test_tree_with_utf8(self):
132
180
tree = self.make_branch_and_tree('.')
133
181
tree = self.get_tree_with_utf8(tree)