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 |
import time |
|
22 |
||
23 |
from bzrlib import ( |
|
24 |
errors, |
|
25 |
inventory, |
|
26 |
)
|
|
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
27 |
from bzrlib.tests.per_workingtree 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 |
||
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
46 |
class TestApplyInventoryDelta(TestCaseWithWorkingTree): |
47 |
||
48 |
def test_add(self): |
|
49 |
wt = self.make_branch_and_tree('.') |
|
50 |
wt.lock_write() |
|
51 |
self.addCleanup(wt.unlock) |
|
52 |
root_id = wt.get_root_id() |
|
53 |
wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id', |
|
54 |
inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')), |
|
55 |
(None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id', |
|
56 |
'bar', parent_id=root_id))]) |
|
57 |
self.assertEqual('bar/foo', wt.inventory.id2path('foo-id')) |
|
58 |
self.assertEqual('bar', wt.inventory.id2path('bar-id')) |
|
59 |
||
60 |
def test_remove(self): |
|
61 |
wt = self.make_branch_and_tree('.') |
|
62 |
wt.lock_write() |
|
63 |
self.addCleanup(wt.unlock) |
|
64 |
self.build_tree(['foo/', 'foo/bar']) |
|
65 |
wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id']) |
|
66 |
wt.apply_inventory_delta([('foo', None, 'foo-id', None), |
|
67 |
('foo/bar', None, 'bar-id', None)]) |
|
68 |
self.assertIs(None, wt.path2id('foo')) |
|
69 |
||
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
70 |
def test_rename_dir_with_children(self): |
71 |
wt = self.make_branch_and_tree('.') |
|
72 |
wt.lock_write() |
|
73 |
root_id = wt.get_root_id() |
|
74 |
self.addCleanup(wt.unlock) |
|
75 |
self.build_tree(['foo/', 'foo/bar']) |
|
76 |
wt.add(['foo', 'foo/bar'], |
|
77 |
['foo-id', 'bar-id']) |
|
78 |
wt.apply_inventory_delta([('foo', 'baz', 'foo-id', |
|
79 |
inventory.InventoryDirectory('foo-id', 'baz', root_id))]) |
|
80 |
# 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 |
81 |
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. |
82 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
83 |
||
84 |
def test_rename_dir_with_children_with_children(self): |
|
85 |
wt = self.make_branch_and_tree('.') |
|
86 |
wt.lock_write() |
|
87 |
root_id = wt.get_root_id() |
|
88 |
self.addCleanup(wt.unlock) |
|
89 |
self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz']) |
|
90 |
wt.add(['foo', 'foo/bar', 'foo/bar/baz'], |
|
91 |
['foo-id', 'bar-id', 'baz-id']) |
|
92 |
wt.apply_inventory_delta([('foo', 'quux', 'foo-id', |
|
93 |
inventory.InventoryDirectory('foo-id', 'quux', root_id))]) |
|
94 |
# foo/bar/baz should have been followed the rename of its parent's
|
|
95 |
# parent to quux/bar/baz
|
|
96 |
self.assertEqual('quux/bar/baz', wt.id2path('baz-id')) |
|
97 |
||
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
98 |
def test_rename_file(self): |
99 |
wt = self.make_branch_and_tree('.') |
|
100 |
wt.lock_write() |
|
101 |
self.addCleanup(wt.unlock) |
|
102 |
self.build_tree(['foo/', 'foo/bar', 'baz/']) |
|
103 |
wt.add(['foo', 'foo/bar', 'baz'], |
|
104 |
['foo-id', 'bar-id', 'baz-id']) |
|
105 |
wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id', |
|
106 |
inventory.InventoryFile('bar-id', 'bar', 'baz-id'))]) |
|
107 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
108 |
||
109 |
def test_rename_swap(self): |
|
110 |
"""Test the swap-names edge case.
|
|
111 |
||
112 |
foo and bar should swap names, but retain their children. If this
|
|
113 |
works, any simpler rename ought to work.
|
|
114 |
"""
|
|
115 |
wt = self.make_branch_and_tree('.') |
|
116 |
wt.lock_write() |
|
117 |
root_id = wt.get_root_id() |
|
118 |
self.addCleanup(wt.unlock) |
|
119 |
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux']) |
|
120 |
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'], |
|
121 |
['foo-id', 'bar-id', 'baz-id', 'qux-id']) |
|
122 |
wt.apply_inventory_delta([('foo', 'baz', 'foo-id', |
|
123 |
inventory.InventoryDirectory('foo-id', 'baz', root_id)), |
|
124 |
('baz', 'foo', 'baz-id', |
|
125 |
inventory.InventoryDirectory('baz-id', 'foo', root_id))]) |
|
126 |
self.assertEqual('baz/bar', wt.id2path('bar-id')) |
|
127 |
self.assertEqual('foo/qux', wt.id2path('qux-id')) |
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
128 |
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
129 |
def test_child_rename_ordering(self): |
130 |
"""Test the rename-parent, move child edge case.
|
|
131 |
||
132 |
(A naive implementation may move the parent first, and then be
|
|
133 |
unable to find the child.)
|
|
134 |
"""
|
|
135 |
wt = self.make_branch_and_tree('.') |
|
136 |
root_id = wt.get_root_id() |
|
137 |
self.build_tree(['dir/', 'dir/child', 'other/']) |
|
138 |
wt.add(['dir', 'dir/child', 'other'], |
|
139 |
['dir-id', 'child-id', 'other-id']) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
140 |
# this delta moves dir-id to dir2 and reparents
|
2865.1.3
by Robert Collins
Review feedback. |
141 |
# child-id to a parent of other-id
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
142 |
wt.apply_inventory_delta([('dir', 'dir2', 'dir-id', |
143 |
inventory.InventoryDirectory('dir-id', 'dir2', root_id)), |
|
144 |
('dir/child', 'other/child', 'child-id', |
|
145 |
inventory.InventoryFile('child-id', 'child', 'other-id'))]) |
|
146 |
self.assertEqual('dir2', wt.id2path('dir-id')) |
|
147 |
self.assertEqual('other/child', wt.id2path('child-id')) |
|
148 |
||
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
149 |
def test_replace_root(self): |
150 |
wt = self.make_branch_and_tree('.') |
|
151 |
wt.lock_write() |
|
152 |
self.addCleanup(wt.unlock) |
|
153 |
||
154 |
root_id = wt.get_root_id() |
|
155 |
wt.apply_inventory_delta([('', None, root_id, None), |
|
156 |
(None, '', 'root-id', |
|
157 |
inventory.InventoryDirectory('root-id', '', None))]) |