bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
1 |
# Copyright (C) 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 interface conformance of inventories of trees."""
|
|
18 |
||
19 |
||
20 |
from cStringIO import StringIO |
|
21 |
import os |
|
22 |
||
23 |
from bzrlib.diff import internal_diff |
|
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
24 |
from bzrlib.mutabletree import MutableTree |
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
25 |
from bzrlib.osutils import has_symlinks |
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
26 |
from bzrlib.symbol_versioning import zero_ninetyone, one_zero |
|
3363.2.7
by Aaron Bentley
Implement alterntative-to-inventory tests |
27 |
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
28 |
from bzrlib.tests.tree_implementations import TestCaseWithTree |
29 |
from bzrlib.uncommit import uncommit |
|
30 |
||
31 |
||
|
3363.2.7
by Aaron Bentley
Implement alterntative-to-inventory tests |
32 |
def get_inventory_if_applicable(tree): |
33 |
try: |
|
34 |
return tree.inventory |
|
35 |
except NotImplementedError: |
|
36 |
raise TestNotApplicable('Tree does not implement inventory') |
|
37 |
||
38 |
||
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
39 |
class TestEntryDiffing(TestCaseWithTree): |
40 |
||
41 |
def setUp(self): |
|
42 |
super(TestEntryDiffing, self).setUp() |
|
43 |
self.wt = self.make_branch_and_tree('.') |
|
44 |
self.branch = self.wt.branch |
|
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
45 |
open('file', 'wb').write('foo\n') |
46 |
open('binfile', 'wb').write('foo\n') |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
47 |
self.wt.add(['file'], ['fileid']) |
48 |
self.wt.add(['binfile'], ['binfileid']) |
|
49 |
if has_symlinks(): |
|
50 |
os.symlink('target1', 'symlink') |
|
51 |
self.wt.add(['symlink'], ['linkid']) |
|
52 |
self.wt.commit('message_1', rev_id = '1') |
|
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
53 |
open('file', 'wb').write('bar\n') |
54 |
open('binfile', 'wb').write('x' * 1023 + '\x00\n') |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
55 |
if has_symlinks(): |
56 |
os.unlink('symlink') |
|
57 |
os.symlink('target2', 'symlink') |
|
58 |
self.tree_1 = self.branch.repository.revision_tree('1') |
|
59 |
self.inv_1 = self.branch.repository.get_inventory('1') |
|
60 |
self.file_1 = self.inv_1['fileid'] |
|
61 |
self.file_1b = self.inv_1['binfileid'] |
|
62 |
self.tree_2 = self.workingtree_to_test_tree(self.wt) |
|
63 |
self.tree_2.lock_read() |
|
64 |
self.addCleanup(self.tree_2.unlock) |
|
|
3363.2.7
by Aaron Bentley
Implement alterntative-to-inventory tests |
65 |
self.inv_2 = get_inventory_if_applicable(self.tree_2) |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
66 |
self.file_2 = self.inv_2['fileid'] |
67 |
self.file_2b = self.inv_2['binfileid'] |
|
68 |
if has_symlinks(): |
|
69 |
self.link_1 = self.inv_1['linkid'] |
|
70 |
self.link_2 = self.inv_2['linkid'] |
|
71 |
||
72 |
def test_file_diff_deleted(self): |
|
73 |
output = StringIO() |
|
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
74 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
75 |
self.file_1.diff, |
76 |
internal_diff, |
|
77 |
"old_label", self.tree_1, |
|
78 |
"/dev/null", None, None, |
|
79 |
output) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
80 |
self.assertEqual(output.getvalue(), "--- old_label\n" |
81 |
"+++ /dev/null\n" |
|
82 |
"@@ -1,1 +0,0 @@\n" |
|
83 |
"-foo\n" |
|
84 |
"\n") |
|
85 |
||
86 |
def test_file_diff_added(self): |
|
87 |
output = StringIO() |
|
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
88 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
89 |
self.file_1.diff, |
90 |
internal_diff, |
|
91 |
"new_label", self.tree_1, |
|
92 |
"/dev/null", None, None, |
|
93 |
output, reverse=True) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
94 |
self.assertEqual(output.getvalue(), "--- /dev/null\n" |
95 |
"+++ new_label\n" |
|
96 |
"@@ -0,0 +1,1 @@\n" |
|
97 |
"+foo\n" |
|
98 |
"\n") |
|
99 |
||
100 |
def test_file_diff_changed(self): |
|
101 |
output = StringIO() |
|
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
102 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
103 |
self.file_1.diff, |
104 |
internal_diff, |
|
105 |
"/dev/null", self.tree_1, |
|
106 |
"new_label", self.file_2, self.tree_2, |
|
107 |
output) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
108 |
self.assertEqual(output.getvalue(), "--- /dev/null\n" |
109 |
"+++ new_label\n" |
|
110 |
"@@ -1,1 +1,1 @@\n" |
|
111 |
"-foo\n" |
|
112 |
"+bar\n" |
|
113 |
"\n") |
|
114 |
||
115 |
def test_file_diff_binary(self): |
|
116 |
output = StringIO() |
|
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
117 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
118 |
self.file_1.diff, |
119 |
internal_diff, |
|
120 |
"/dev/null", self.tree_1, |
|
121 |
"new_label", self.file_2b, self.tree_2, |
|
122 |
output) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
123 |
self.assertEqual(output.getvalue(), |
124 |
"Binary files /dev/null and new_label differ\n") |
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
125 |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
126 |
def test_link_diff_deleted(self): |
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
127 |
self.requireFeature(SymlinkFeature) |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
128 |
output = StringIO() |
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
129 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
130 |
self.link_1.diff, |
131 |
internal_diff, "old_label", |
|
132 |
self.tree_1, "/dev/null", None, None, |
|
133 |
output) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
134 |
self.assertEqual(output.getvalue(), |
135 |
"=== target was 'target1'\n") |
|
136 |
||
137 |
def test_link_diff_added(self): |
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
138 |
self.requireFeature(SymlinkFeature) |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
139 |
output = StringIO() |
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
140 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
141 |
self.link_1.diff, |
142 |
internal_diff, |
|
143 |
"new_label", self.tree_1, |
|
144 |
"/dev/null", None, None, |
|
145 |
output, reverse=True) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
146 |
self.assertEqual(output.getvalue(), |
147 |
"=== target is 'target1'\n") |
|
148 |
||
149 |
def test_link_diff_changed(self): |
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
150 |
self.requireFeature(SymlinkFeature) |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
151 |
output = StringIO() |
|
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
152 |
self.applyDeprecated(one_zero, |
|
3009.2.32
by Aaron Bentley
InventoryEntry.diff is now deprecated |
153 |
self.link_1.diff, |
154 |
internal_diff, |
|
155 |
"/dev/null", self.tree_1, |
|
156 |
"new_label", self.link_2, self.tree_2, |
|
157 |
output) |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
158 |
self.assertEqual(output.getvalue(), |
159 |
"=== target changed 'target1' => 'target2'\n") |
|
160 |
||
161 |
||
162 |
class TestPreviousHeads(TestCaseWithTree): |
|
163 |
||
164 |
def setUp(self): |
|
165 |
# we want several inventories, that respectively
|
|
166 |
# give use the following scenarios:
|
|
167 |
# A) fileid not in any inventory (A),
|
|
168 |
# B) fileid present in one inventory (B) and (A,B)
|
|
169 |
# C) fileid present in two inventories, and they
|
|
170 |
# are not mutual descendents (B, C)
|
|
171 |
# D) fileid present in two inventories and one is
|
|
172 |
# a descendent of the other. (B, D)
|
|
173 |
super(TestPreviousHeads, self).setUp() |
|
174 |
self.wt = self.make_branch_and_tree('.') |
|
175 |
self.branch = self.wt.branch |
|
176 |
self.build_tree(['file']) |
|
177 |
self.wt.commit('new branch', allow_pointless=True, rev_id='A') |
|
178 |
self.inv_A = self.branch.repository.get_inventory('A') |
|
179 |
self.wt.add(['file'], ['fileid']) |
|
180 |
self.wt.commit('add file', rev_id='B') |
|
181 |
self.inv_B = self.branch.repository.get_inventory('B') |
|
182 |
uncommit(self.branch, tree=self.wt) |
|
183 |
self.assertEqual(self.branch.revision_history(), ['A']) |
|
184 |
self.wt.commit('another add of file', rev_id='C') |
|
185 |
self.inv_C = self.branch.repository.get_inventory('C') |
|
186 |
self.wt.add_parent_tree_id('B') |
|
187 |
self.wt.commit('merge in B', rev_id='D') |
|
188 |
self.inv_D = self.branch.repository.get_inventory('D') |
|
189 |
self.tree = self.workingtree_to_test_tree(self.wt) |
|
190 |
self.tree.lock_read() |
|
191 |
self.addCleanup(self.tree.unlock) |
|
|
3363.2.7
by Aaron Bentley
Implement alterntative-to-inventory tests |
192 |
self.file_active = get_inventory_if_applicable(self.tree)['fileid'] |
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
193 |
self.weave = self.branch.repository.weave_store.get_weave('fileid', |
194 |
self.branch.repository.get_transaction()) |
|
195 |
||
196 |
def get_previous_heads(self, inventories): |
|
|
2776.3.1
by Robert Collins
* Deprecated method ``find_previous_heads`` on |
197 |
return self.applyDeprecated(zero_ninetyone, |
198 |
self.file_active.find_previous_heads, |
|
199 |
inventories, |
|
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
200 |
self.branch.repository.weave_store, |
201 |
self.branch.repository.get_transaction()) |
|
202 |
||
203 |
def test_fileid_in_no_inventory(self): |
|
204 |
self.assertEqual({}, self.get_previous_heads([self.inv_A])) |
|
205 |
||
206 |
def test_fileid_in_one_inventory(self): |
|
207 |
self.assertEqual({'B':self.inv_B['fileid']}, |
|
208 |
self.get_previous_heads([self.inv_B])) |
|
209 |
self.assertEqual({'B':self.inv_B['fileid']}, |
|
210 |
self.get_previous_heads([self.inv_A, self.inv_B])) |
|
211 |
self.assertEqual({'B':self.inv_B['fileid']}, |
|
212 |
self.get_previous_heads([self.inv_B, self.inv_A])) |
|
213 |
||
214 |
def test_fileid_in_two_inventories_gives_both_entries(self): |
|
215 |
self.assertEqual({'B':self.inv_B['fileid'], |
|
216 |
'C':self.inv_C['fileid']}, |
|
217 |
self.get_previous_heads([self.inv_B, self.inv_C])) |
|
218 |
self.assertEqual({'B':self.inv_B['fileid'], |
|
219 |
'C':self.inv_C['fileid']}, |
|
220 |
self.get_previous_heads([self.inv_C, self.inv_B])) |
|
221 |
||
222 |
def test_fileid_in_two_inventories_already_merged_gives_head(self): |
|
223 |
self.assertEqual({'D':self.inv_D['fileid']}, |
|
224 |
self.get_previous_heads([self.inv_B, self.inv_D])) |
|
225 |
self.assertEqual({'D':self.inv_D['fileid']}, |
|
226 |
self.get_previous_heads([self.inv_D, self.inv_B])) |
|
227 |
||
228 |
# TODO: test two inventories with the same file revision
|
|
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
229 |
|
230 |
||
231 |
class TestInventory(TestCaseWithTree): |
|
232 |
||
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
233 |
def _set_up(self): |
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
234 |
self.tree = self.get_tree_with_subdirs_and_all_content_types() |
235 |
self.tree.lock_read() |
|
236 |
self.addCleanup(self.tree.unlock) |
|
237 |
# Commenting out the following line still fails.
|
|
|
3363.2.7
by Aaron Bentley
Implement alterntative-to-inventory tests |
238 |
self.inv = get_inventory_if_applicable(self.tree) |
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
239 |
|
240 |
def test_symlink_target(self): |
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
241 |
self.requireFeature(SymlinkFeature) |
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
242 |
self._set_up() |
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
243 |
if isinstance(self.tree, MutableTree): |
244 |
raise TestSkipped( |
|
245 |
'symlinks not accurately represented in working trees') |
|
246 |
entry = self.inv[self.inv.path2id('symlink')] |
|
247 |
self.assertEqual(entry.symlink_target, 'link-target') |
|
248 |
||
249 |
def test_symlink(self): |
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
250 |
self.requireFeature(SymlinkFeature) |
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
251 |
self._set_up() |
|
2338.4.9
by Marien Zwart
More tests for symlinks in tree inventories. |
252 |
entry = self.inv[self.inv.path2id('symlink')] |
253 |
self.assertEqual(entry.kind, 'symlink') |
|
254 |
self.assertEqual(None, entry.text_size) |