bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
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 |
||
|
2338.4.6
by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations. |
17 |
"""Tests for interface conformance of inventories of working trees."""
|
18 |
||
19 |
||
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
20 |
import os |
21 |
import time |
|
22 |
||
23 |
from bzrlib import ( |
|
24 |
errors, |
|
25 |
inventory, |
|
26 |
)
|
|
|
2338.4.3
by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations. |
27 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
28 |
|
29 |
||
|
2338.4.3
by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations. |
30 |
class TestRevert(TestCaseWithWorkingTree): |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
31 |
|
32 |
def test_dangling_id(self): |
|
33 |
wt = self.make_branch_and_tree('b1') |
|
34 |
wt.lock_tree_write() |
|
35 |
self.addCleanup(wt.unlock) |
|
36 |
self.assertEqual(len(wt.inventory), 1) |
|
37 |
open('b1/a', 'wb').write('a test\n') |
|
38 |
wt.add('a') |
|
39 |
self.assertEqual(len(wt.inventory), 2) |
|
40 |
wt.flush() # workaround revert doing wt._write_inventory for now. |
|
41 |
os.unlink('b1/a') |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
42 |
wt.revert() |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
43 |
self.assertEqual(len(wt.inventory), 1) |
44 |
||
45 |
||
|
2338.4.3
by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations. |
46 |
class TestSnapshot(TestCaseWithWorkingTree): |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
47 |
|
48 |
def setUp(self): |
|
49 |
# for full testing we'll need a branch
|
|
50 |
# with a subdir to test parent changes.
|
|
51 |
# and a file, link and dir under that.
|
|
52 |
# but right now I only need one attribute
|
|
53 |
# to change, and then test merge patterns
|
|
54 |
# with fake parent entries.
|
|
55 |
super(TestSnapshot, self).setUp() |
|
56 |
self.wt = self.make_branch_and_tree('.') |
|
57 |
self.branch = self.wt.branch |
|
58 |
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary') |
|
59 |
self.wt.add(['subdir', 'subdir/file'], |
|
60 |
['dirid', 'fileid']) |
|
61 |
self.wt.commit('message_1', rev_id = '1') |
|
62 |
self.tree_1 = self.branch.repository.revision_tree('1') |
|
63 |
self.inv_1 = self.branch.repository.get_inventory('1') |
|
64 |
self.file_1 = self.inv_1['fileid'] |
|
65 |
self.wt.lock_write() |
|
66 |
self.addCleanup(self.wt.unlock) |
|
67 |
self.file_active = self.wt.inventory['fileid'] |
|
68 |
self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2') |
|
69 |
||
70 |
def test_snapshot_new_revision(self): |
|
71 |
# This tests that a simple commit with no parents makes a new
|
|
72 |
# revision value in the inventory entry
|
|
73 |
self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder) |
|
74 |
# expected outcome - file_1 has a revision id of '2', and we can get
|
|
75 |
# its text of 'file contents' out of the weave.
|
|
76 |
self.assertEqual(self.file_1.revision, '1') |
|
77 |
self.assertEqual(self.file_active.revision, '2') |
|
78 |
# this should be a separate test probably, but lets check it once..
|
|
79 |
lines = self.branch.repository.weave_store.get_weave( |
|
80 |
'fileid', |
|
|
2375.1.7
by Andrew Bennetts
Fix test_snapshot_new_revision to use branch.repository.get_transaction instead of branch.get_transaction. |
81 |
self.branch.repository.get_transaction()).get_lines('2') |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
82 |
self.assertEqual(lines, ['contents of subdir/file\n']) |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
83 |
self.wt.branch.repository.commit_write_group() |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
84 |
|
85 |
def test_snapshot_unchanged(self): |
|
86 |
#This tests that a simple commit does not make a new entry for
|
|
87 |
# an unchanged inventory entry
|
|
88 |
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1}, |
|
89 |
self.wt, self.builder) |
|
90 |
self.assertEqual(self.file_1.revision, '1') |
|
91 |
self.assertEqual(self.file_active.revision, '1') |
|
92 |
vf = self.branch.repository.weave_store.get_weave( |
|
93 |
'fileid', |
|
94 |
self.branch.repository.get_transaction()) |
|
95 |
self.assertRaises(errors.RevisionNotPresent, |
|
96 |
vf.get_lines, |
|
97 |
'2') |
|
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
98 |
self.wt.branch.repository.commit_write_group() |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
99 |
|
100 |
def test_snapshot_merge_identical_different_revid(self): |
|
101 |
# This tests that a commit with two identical parents, one of which has
|
|
102 |
# a different revision id, results in a new revision id in the entry.
|
|
103 |
# 1->other, commit a merge of other against 1, results in 2.
|
|
104 |
other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id) |
|
105 |
other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id) |
|
106 |
other_ie.revision = '1' |
|
107 |
other_ie.text_sha1 = self.file_1.text_sha1 |
|
108 |
other_ie.text_size = self.file_1.text_size |
|
109 |
self.assertEqual(self.file_1, other_ie) |
|
110 |
other_ie.revision = 'other' |
|
111 |
self.assertNotEqual(self.file_1, other_ie) |
|
112 |
versionfile = self.branch.repository.weave_store.get_weave( |
|
113 |
'fileid', self.branch.repository.get_transaction()) |
|
114 |
versionfile.clone_text('other', '1', ['1']) |
|
115 |
self.file_active.snapshot('2', 'subdir/file', |
|
116 |
{'1':self.file_1, 'other':other_ie}, |
|
117 |
self.wt, self.builder) |
|
118 |
self.assertEqual(self.file_active.revision, '2') |
|
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
119 |
self.wt.branch.repository.commit_write_group() |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
120 |
|
121 |
def test_snapshot_changed(self): |
|
122 |
# This tests that a commit with one different parent results in a new
|
|
123 |
# revision id in the entry.
|
|
124 |
self.wt.rename_one('subdir/file', 'subdir/newname') |
|
125 |
self.file_active = self.wt.inventory['fileid'] |
|
126 |
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, |
|
127 |
self.wt, self.builder) |
|
128 |
# expected outcome - file_1 has a revision id of '2'
|
|
129 |
self.assertEqual(self.file_active.revision, '2') |
|
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
130 |
self.wt.branch.repository.commit_write_group() |
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
131 |
|
132 |
||
133 |
class TestApplyInventoryDelta(TestCaseWithWorkingTree): |
|
134 |
||
135 |
def test_add(self): |
|
136 |
wt = self.make_branch_and_tree('.') |
|
137 |
wt.lock_write() |
|
138 |
self.addCleanup(wt.unlock) |
|
139 |
root_id = wt.get_root_id() |
|
140 |
wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id', |
|
141 |
inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')), |
|
142 |
(None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id', |
|
143 |
'bar', parent_id=root_id))]) |
|
144 |
self.assertEqual('bar/foo', wt.inventory.id2path('foo-id')) |
|
145 |
self.assertEqual('bar', wt.inventory.id2path('bar-id')) |
|
146 |
||
147 |
def test_remove(self): |
|
148 |
wt = self.make_branch_and_tree('.') |
|
149 |
wt.lock_write() |
|
150 |
self.addCleanup(wt.unlock) |
|
151 |
self.build_tree(['foo/', 'foo/bar']) |
|
152 |
wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id']) |
|
153 |
wt.apply_inventory_delta([('foo', None, 'foo-id', None), |
|
154 |
('foo/bar', None, 'bar-id', None)]) |
|
155 |
self.assertIs(None, wt.path2id('foo')) |
|
156 |
||
157 |
def test_rename_file(self): |
|
158 |
wt = self.make_branch_and_tree('.') |
|
159 |
wt.lock_write() |
|
160 |
root_id = wt.get_root_id() |
|
161 |
self.addCleanup(wt.unlock) |
|
162 |
self.build_tree(['foo/', 'foo/bar', 'baz/']) |
|
163 |
wt.add(['foo', 'foo/bar', 'baz'], |
|
164 |
['foo-id', 'bar-id', 'baz-id']) |
|
165 |
wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id', |
|
166 |
inventory.InventoryFile('bar-id', 'bar', 'baz-id'))]) |
|
167 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
168 |
||
169 |
def test_rename_swap(self): |
|
170 |
"""Test the swap-names edge case. |
|
171 |
||
172 |
foo and bar should swap names, but retain their children. If this
|
|
173 |
works, any simpler rename ought to work.
|
|
174 |
"""
|
|
175 |
wt = self.make_branch_and_tree('.') |
|
176 |
wt.lock_write() |
|
177 |
root_id = wt.get_root_id() |
|
178 |
self.addCleanup(wt.unlock) |
|
179 |
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux']) |
|
180 |
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'], |
|
181 |
['foo-id', 'bar-id', 'baz-id', 'qux-id']) |
|
182 |
wt.apply_inventory_delta([('foo', 'baz', 'foo-id', |
|
183 |
inventory.InventoryDirectory('foo-id', 'baz', root_id)), |
|
184 |
('baz', 'foo', 'baz-id', |
|
185 |
inventory.InventoryDirectory('baz-id', 'foo', root_id))]) |
|
186 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
187 |
self.assertEqual('foo/qux', wt.id2path('qux-id')) |
|
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
188 |
|
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
189 |
def test_child_rename_ordering(self): |
190 |
"""Test the rename-parent, move child edge case. |
|
191 |
||
192 |
(A naive implementation may move the parent first, and then be
|
|
193 |
unable to find the child.)
|
|
194 |
"""
|
|
195 |
wt = self.make_branch_and_tree('.') |
|
196 |
root_id = wt.get_root_id() |
|
197 |
self.build_tree(['dir/', 'dir/child', 'other/']) |
|
198 |
wt.add(['dir', 'dir/child', 'other'], |
|
199 |
['dir-id', 'child-id', 'other-id']) |
|
200 |
wt.apply_inventory_delta([('dir', 'dir2', 'dir-id', |
|
201 |
inventory.InventoryDirectory('dir-id', 'dir2', root_id)), |
|
202 |
('dir/child', 'other/child', 'child-id', |
|
203 |
inventory.InventoryFile('child-id', 'child', 'other-id'))]) |
|
204 |
self.assertEqual('dir2', wt.id2path('dir-id')) |
|
205 |
self.assertEqual('other/child', wt.id2path('child-id')) |
|
206 |
||
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
207 |
def test_replace_root(self): |
208 |
wt = self.make_branch_and_tree('.') |
|
209 |
wt.lock_write() |
|
210 |
self.addCleanup(wt.unlock) |
|
211 |
||
212 |
root_id = wt.get_root_id() |
|
213 |
wt.apply_inventory_delta([('', None, root_id, None), |
|
214 |
(None, '', 'root-id', |
|
215 |
inventory.InventoryDirectory('root-id', '', None))]) |