2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2006 Canonical Ltd
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
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.tree_implementations import TestCaseWithTree |
|
20 |
||
21 |
||
22 |
class TestTreeShapes(TestCaseWithTree): |
|
23 |
||
24 |
def test_empty_tree_no_parents(self): |
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
25 |
tree = self.make_branch_and_tree('.') |
26 |
tree = self.get_tree_no_parents_no_content(tree) |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
27 |
self.assertEqual([], tree.get_parent_ids()) |
28 |
self.assertEqual([], tree.conflicts()) |
|
29 |
self.assertEqual([], list(tree.unknowns())) |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
30 |
self.assertEqual(['empty-root-id'], list(iter(tree))) |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
31 |
self.assertEqual( |
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
32 |
[('', 'empty-root-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
33 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
34 |
||
35 |
def test_abc_tree_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
36 |
tree = self.make_branch_and_tree('.') |
37 |
tree = self.get_tree_no_parents_abc_content(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
38 |
self.assertEqual([], tree.get_parent_ids()) |
39 |
self.assertEqual([], tree.conflicts()) |
|
40 |
self.assertEqual([], list(tree.unknowns())) |
|
41 |
# __iter__ has no strongly defined order
|
|
42 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
43 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
44 |
set(iter(tree))) |
45 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
46 |
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
47 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
48 |
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id')) |
|
49 |
self.assertFalse(tree.is_executable('c-id')) |
|
50 |
||
51 |
def test_abc_tree_content_2_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
52 |
tree = self.make_branch_and_tree('.') |
53 |
tree = self.get_tree_no_parents_abc_content_2(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
54 |
self.assertEqual([], tree.get_parent_ids()) |
55 |
self.assertEqual([], tree.conflicts()) |
|
56 |
self.assertEqual([], list(tree.unknowns())) |
|
57 |
# __iter__ has no strongly defined order
|
|
58 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
59 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
60 |
set(iter(tree))) |
61 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
62 |
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
63 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
64 |
self.assertEqualDiff('foobar\n', tree.get_file_text('a-id')) |
|
65 |
self.assertFalse(tree.is_executable('c-id')) |
|
66 |
||
67 |
def test_abc_tree_content_3_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
68 |
tree = self.make_branch_and_tree('.') |
69 |
tree = self.get_tree_no_parents_abc_content_3(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
70 |
self.assertEqual([], tree.get_parent_ids()) |
71 |
self.assertEqual([], tree.conflicts()) |
|
72 |
self.assertEqual([], list(tree.unknowns())) |
|
73 |
# __iter__ has no strongly defined order
|
|
74 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
75 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
76 |
set(iter(tree))) |
77 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
78 |
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('b/c', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
79 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
80 |
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id')) |
|
81 |
self.assertTrue(tree.is_executable('c-id')) |
|
82 |
||
83 |
def test_abc_tree_content_4_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
84 |
tree = self.make_branch_and_tree('.') |
85 |
tree = self.get_tree_no_parents_abc_content_4(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
86 |
self.assertEqual([], tree.get_parent_ids()) |
87 |
self.assertEqual([], tree.conflicts()) |
|
88 |
self.assertEqual([], list(tree.unknowns())) |
|
89 |
# __iter__ has no strongly defined order
|
|
90 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
91 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
92 |
set(iter(tree))) |
93 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
94 |
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
95 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
96 |
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id')) |
|
97 |
self.assertFalse(tree.is_executable('c-id')) |
|
98 |
||
99 |
def test_abc_tree_content_5_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
100 |
tree = self.make_branch_and_tree('.') |
101 |
tree = self.get_tree_no_parents_abc_content_5(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
102 |
self.assertEqual([], tree.get_parent_ids()) |
103 |
self.assertEqual([], tree.conflicts()) |
|
104 |
self.assertEqual([], list(tree.unknowns())) |
|
105 |
# __iter__ has no strongly defined order
|
|
106 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
107 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
108 |
set(iter(tree))) |
109 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
110 |
[('', 'root-id'), ('b', 'b-id'), ('d', 'a-id'), ('b/c', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
111 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
112 |
self.assertEqualDiff('bar\n', tree.get_file_text('a-id')) |
|
113 |
self.assertFalse(tree.is_executable('c-id')) |
|
114 |
||
115 |
def test_abc_tree_content_6_no_parents(self): |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
116 |
tree = self.make_branch_and_tree('.') |
117 |
tree = self.get_tree_no_parents_abc_content_6(tree) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
118 |
self.assertEqual([], tree.get_parent_ids()) |
119 |
self.assertEqual([], tree.conflicts()) |
|
120 |
self.assertEqual([], list(tree.unknowns())) |
|
121 |
# __iter__ has no strongly defined order
|
|
122 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
123 |
set(['root-id', 'a-id', 'b-id', 'c-id']), |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
124 |
set(iter(tree))) |
125 |
self.assertEqual( |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
126 |
[('', 'root-id'), ('a', 'a-id'), ('b', 'b-id'), ('e', 'c-id')], |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
127 |
[(path, node.file_id) for path, node in tree.iter_entries_by_dir()]) |
128 |
self.assertEqualDiff('contents of a\n', tree.get_file_text('a-id')) |
|
129 |
self.assertTrue(tree.is_executable('c-id')) |
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
130 |
|
131 |
def test_tree_with_utf8(self): |
|
132 |
tree = self.make_branch_and_tree('.') |
|
133 |
tree = self.get_tree_with_utf8(tree) |
|
2294.1.2
by John Arbash Meinel
Track down and add tests that all tree.commit() can handle |
134 |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
135 |
revision_id = u'r\xe9v-1'.encode('utf8') |
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
136 |
root_id = 'TREE_ROOT' |
137 |
bar_id = u'b\xe5r-id'.encode('utf8') |
|
138 |
foo_id = u'f\xf6-id'.encode('utf8') |
|
139 |
baz_id = u'b\xe1z-id'.encode('utf8') |
|
140 |
path_and_ids = [(u'', root_id, None), |
|
141 |
(u'b\xe5r', bar_id, root_id), |
|
142 |
(u'f\xf6', foo_id, root_id), |
|
143 |
(u'b\xe5r/b\xe1z', baz_id, bar_id), |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
144 |
]
|
145 |
tree.lock_read() |
|
146 |
try: |
|
147 |
path_entries = list(tree.iter_entries_by_dir()) |
|
148 |
finally: |
|
149 |
tree.unlock() |
|
150 |
||
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
151 |
for expected, (path, ie) in zip(path_and_ids, path_entries): |
152 |
self.assertEqual(expected[0], path) # Paths should match |
|
153 |
self.assertIsInstance(path, unicode) |
|
154 |
self.assertEqual(expected[1], ie.file_id) |
|
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
155 |
self.assertIsInstance(ie.file_id, str) |
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
156 |
self.assertEqual(expected[2], ie.parent_id) |
157 |
if expected[2] is not None: |
|
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
158 |
self.assertIsInstance(ie.parent_id, str) |
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
159 |
# WorkingTree's return None for the last modified revision
|
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
160 |
if ie.revision is not None: |
161 |
self.assertIsInstance(ie.revision, str) |
|
162 |
if expected[0] != '': |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
163 |
# Some trees will preserve the revision id of the tree root,
|
164 |
# but not all will
|
|
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
165 |
self.assertEqual(revision_id, ie.revision) |
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
166 |
self.assertEqual(len(path_and_ids), len(path_entries)) |
167 |
get_revision_id = getattr(tree, 'get_revision_id', None) |
|
168 |
if get_revision_id is not None: |
|
169 |
self.assertIsInstance(get_revision_id(), str) |
|
170 |
last_revision = getattr(tree, 'last_revision', None) |
|
171 |
if last_revision is not None: |
|
172 |
self.assertIsInstance(last_revision(), str) |
|
173 |
||
2294.1.2
by John Arbash Meinel
Track down and add tests that all tree.commit() can handle |
174 |
def test_tree_with_merged_utf8(self): |
175 |
tree = self.make_branch_and_tree('.') |
|
176 |
tree = self.get_tree_with_merged_utf8(tree) |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
177 |
|
178 |
revision_id_1 = u'r\xe9v-1'.encode('utf8') |
|
179 |
revision_id_2 = u'r\xe9v-2'.encode('utf8') |
|
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
180 |
root_id = 'TREE_ROOT' |
181 |
bar_id = u'b\xe5r-id'.encode('utf8') |
|
182 |
foo_id = u'f\xf6-id'.encode('utf8') |
|
183 |
baz_id = u'b\xe1z-id'.encode('utf8') |
|
184 |
zez_id = u'z\xf7z-id'.encode('utf8') |
|
185 |
path_and_ids = [(u'', root_id, None, None), |
|
186 |
(u'b\xe5r', bar_id, root_id, revision_id_1), |
|
187 |
(u'f\xf6', foo_id, root_id, revision_id_1), |
|
188 |
(u'b\xe5r/b\xe1z', baz_id, bar_id, revision_id_1), |
|
189 |
(u'b\xe5r/z\xf7z', zez_id, bar_id, revision_id_2), |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
190 |
]
|
191 |
tree.lock_read() |
|
192 |
try: |
|
193 |
path_entries = list(tree.iter_entries_by_dir()) |
|
194 |
finally: |
|
195 |
tree.unlock() |
|
196 |
||
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
197 |
for expected, (path, ie) in zip(path_and_ids, path_entries): |
198 |
self.assertEqual(expected[0], path) # Paths should match |
|
199 |
self.assertIsInstance(path, unicode) |
|
200 |
self.assertEqual(expected[1], ie.file_id) |
|
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
201 |
self.assertIsInstance(ie.file_id, str) |
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
202 |
self.assertEqual(expected[2], ie.parent_id) |
203 |
if expected[2] is not None: |
|
2294.1.10
by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass |
204 |
self.assertIsInstance(ie.parent_id, str) |
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
205 |
# WorkingTree's return None for the last modified revision
|
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
206 |
if ie.revision is not None: |
207 |
self.assertIsInstance(ie.revision, str) |
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
208 |
if expected[0] == '': |
209 |
# Some trees will preserve the revision id of the tree root,
|
|
210 |
# but not all will
|
|
211 |
continue
|
|
2294.1.7
by John Arbash Meinel
Add tests for parent ids in test_test_trees |
212 |
self.assertEqual(expected[3], ie.revision) |
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
213 |
self.assertEqual(len(path_and_ids), len(path_entries)) |
214 |
get_revision_id = getattr(tree, 'get_revision_id', None) |
|
215 |
if get_revision_id is not None: |
|
216 |
self.assertIsInstance(get_revision_id(), str) |
|
217 |
last_revision = getattr(tree, 'last_revision', None) |
|
218 |
if last_revision is not None: |
|
219 |
self.assertIsInstance(last_revision(), str) |