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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
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 |
||
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
22 |
from bzrlib import inventory, tests |
|
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
23 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
24 |
|
25 |
||
|
2338.4.3
by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations. |
26 |
class TestRevert(TestCaseWithWorkingTree): |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
27 |
|
28 |
def test_dangling_id(self): |
|
29 |
wt = self.make_branch_and_tree('b1') |
|
30 |
wt.lock_tree_write() |
|
31 |
self.addCleanup(wt.unlock) |
|
|
5807.1.3
by Jelmer Vernooij
Avoid inventory. |
32 |
self.assertEqual(len(wt.all_file_ids()), 1) |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
33 |
open('b1/a', 'wb').write('a test\n') |
34 |
wt.add('a') |
|
|
5807.1.3
by Jelmer Vernooij
Avoid inventory. |
35 |
self.assertEqual(len(wt.all_file_ids()), 2) |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
36 |
wt.flush() # workaround revert doing wt._write_inventory for now. |
37 |
os.unlink('b1/a') |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
38 |
wt.revert() |
|
5807.1.3
by Jelmer Vernooij
Avoid inventory. |
39 |
self.assertEqual(len(wt.all_file_ids()), 1) |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
40 |
|
41 |
||
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
42 |
class TestApplyInventoryDelta(TestCaseWithWorkingTree): |
43 |
||
44 |
def test_add(self): |
|
45 |
wt = self.make_branch_and_tree('.') |
|
46 |
wt.lock_write() |
|
47 |
self.addCleanup(wt.unlock) |
|
48 |
root_id = wt.get_root_id() |
|
49 |
wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id', |
|
50 |
inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')), |
|
51 |
(None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id', |
|
52 |
'bar', parent_id=root_id))]) |
|
53 |
self.assertEqual('bar/foo', wt.inventory.id2path('foo-id')) |
|
54 |
self.assertEqual('bar', wt.inventory.id2path('bar-id')) |
|
55 |
||
56 |
def test_remove(self): |
|
57 |
wt = self.make_branch_and_tree('.') |
|
58 |
wt.lock_write() |
|
59 |
self.addCleanup(wt.unlock) |
|
60 |
self.build_tree(['foo/', 'foo/bar']) |
|
61 |
wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id']) |
|
62 |
wt.apply_inventory_delta([('foo', None, 'foo-id', None), |
|
63 |
('foo/bar', None, 'bar-id', None)]) |
|
64 |
self.assertIs(None, wt.path2id('foo')) |
|
65 |
||
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
66 |
def test_rename_dir_with_children(self): |
67 |
wt = self.make_branch_and_tree('.') |
|
68 |
wt.lock_write() |
|
69 |
root_id = wt.get_root_id() |
|
70 |
self.addCleanup(wt.unlock) |
|
71 |
self.build_tree(['foo/', 'foo/bar']) |
|
72 |
wt.add(['foo', 'foo/bar'], |
|
73 |
['foo-id', 'bar-id']) |
|
74 |
wt.apply_inventory_delta([('foo', 'baz', 'foo-id', |
|
75 |
inventory.InventoryDirectory('foo-id', 'baz', root_id))]) |
|
76 |
# foo/bar should have been followed the rename of its parent to baz/bar
|
|
|
3146.8.5
by Aaron Bentley
Get apply_inventory_delta kinda working, but not children |
77 |
self.assertEqual('baz', wt.id2path('foo-id')) |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
78 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
79 |
||
80 |
def test_rename_dir_with_children_with_children(self): |
|
81 |
wt = self.make_branch_and_tree('.') |
|
82 |
wt.lock_write() |
|
83 |
root_id = wt.get_root_id() |
|
84 |
self.addCleanup(wt.unlock) |
|
85 |
self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz']) |
|
86 |
wt.add(['foo', 'foo/bar', 'foo/bar/baz'], |
|
87 |
['foo-id', 'bar-id', 'baz-id']) |
|
88 |
wt.apply_inventory_delta([('foo', 'quux', 'foo-id', |
|
89 |
inventory.InventoryDirectory('foo-id', 'quux', root_id))]) |
|
90 |
# foo/bar/baz should have been followed the rename of its parent's
|
|
91 |
# parent to quux/bar/baz
|
|
92 |
self.assertEqual('quux/bar/baz', wt.id2path('baz-id')) |
|
93 |
||
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
94 |
def test_rename_file(self): |
95 |
wt = self.make_branch_and_tree('.') |
|
96 |
wt.lock_write() |
|
97 |
self.addCleanup(wt.unlock) |
|
98 |
self.build_tree(['foo/', 'foo/bar', 'baz/']) |
|
99 |
wt.add(['foo', 'foo/bar', 'baz'], |
|
100 |
['foo-id', 'bar-id', 'baz-id']) |
|
101 |
wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id', |
|
102 |
inventory.InventoryFile('bar-id', 'bar', 'baz-id'))]) |
|
103 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
104 |
||
105 |
def test_rename_swap(self): |
|
106 |
"""Test the swap-names edge case. |
|
107 |
||
108 |
foo and bar should swap names, but retain their children. If this
|
|
109 |
works, any simpler rename ought to work.
|
|
110 |
"""
|
|
111 |
wt = self.make_branch_and_tree('.') |
|
112 |
wt.lock_write() |
|
113 |
root_id = wt.get_root_id() |
|
114 |
self.addCleanup(wt.unlock) |
|
115 |
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux']) |
|
116 |
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'], |
|
117 |
['foo-id', 'bar-id', 'baz-id', 'qux-id']) |
|
118 |
wt.apply_inventory_delta([('foo', 'baz', 'foo-id', |
|
119 |
inventory.InventoryDirectory('foo-id', 'baz', root_id)), |
|
120 |
('baz', 'foo', 'baz-id', |
|
121 |
inventory.InventoryDirectory('baz-id', 'foo', root_id))]) |
|
122 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
123 |
self.assertEqual('foo/qux', wt.id2path('qux-id')) |
|
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
124 |
|
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
125 |
def test_child_rename_ordering(self): |
126 |
"""Test the rename-parent, move child edge case. |
|
127 |
||
128 |
(A naive implementation may move the parent first, and then be
|
|
129 |
unable to find the child.)
|
|
130 |
"""
|
|
131 |
wt = self.make_branch_and_tree('.') |
|
132 |
root_id = wt.get_root_id() |
|
133 |
self.build_tree(['dir/', 'dir/child', 'other/']) |
|
134 |
wt.add(['dir', 'dir/child', 'other'], |
|
135 |
['dir-id', 'child-id', 'other-id']) |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
136 |
# this delta moves dir-id to dir2 and reparents
|
|
2865.1.3
by Robert Collins
Review feedback. |
137 |
# child-id to a parent of other-id
|
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
138 |
wt.apply_inventory_delta([('dir', 'dir2', 'dir-id', |
139 |
inventory.InventoryDirectory('dir-id', 'dir2', root_id)), |
|
140 |
('dir/child', 'other/child', 'child-id', |
|
141 |
inventory.InventoryFile('child-id', 'child', 'other-id'))]) |
|
142 |
self.assertEqual('dir2', wt.id2path('dir-id')) |
|
143 |
self.assertEqual('other/child', wt.id2path('child-id')) |
|
144 |
||
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
145 |
def test_replace_root(self): |
146 |
wt = self.make_branch_and_tree('.') |
|
147 |
wt.lock_write() |
|
148 |
self.addCleanup(wt.unlock) |
|
149 |
||
150 |
root_id = wt.get_root_id() |
|
151 |
wt.apply_inventory_delta([('', None, root_id, None), |
|
152 |
(None, '', 'root-id', |
|
153 |
inventory.InventoryDirectory('root-id', '', None))]) |
|
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
154 |
|
155 |
||
156 |
class TestTreeReference(TestCaseWithWorkingTree): |
|
157 |
||
158 |
def test_tree_reference_matches_inv(self): |
|
159 |
base = self.make_branch_and_tree('base') |
|
|
5786.1.6
by John Arbash Meinel
Clean up some of the old tests that I had updated. |
160 |
if not base.supports_tree_reference(): |
161 |
raise tests.TestNotApplicable("wt doesn't support nested trees") |
|
162 |
# We add it as a directory, but it becomes a tree-reference
|
|
163 |
base.add(['subdir'], ['subdir-id'], ['directory']) |
|
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
164 |
subdir = self.make_branch_and_tree('base/subdir') |
165 |
self.addCleanup(base.lock_read().unlock) |
|
|
5786.1.6
by John Arbash Meinel
Clean up some of the old tests that I had updated. |
166 |
# Note: we aren't strict about ie.kind being 'directory' here, what we
|
167 |
# are strict about is that wt.inventory should match
|
|
168 |
# wt.current_dirstate()'s idea about what files are where.
|
|
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
169 |
ie = base.inventory['subdir-id'] |
|
5786.1.6
by John Arbash Meinel
Clean up some of the old tests that I had updated. |
170 |
self.assertEqual('directory', ie.kind) |
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
171 |
path, ie = base.iter_entries_by_dir(['subdir-id']).next() |
172 |
self.assertEqual('subdir', path) |
|
173 |
self.assertEqual('tree-reference', ie.kind) |