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