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 |
||
|
6670.4.3
by Jelmer Vernooij
Fix more imports. |
22 |
from breezy import tests |
23 |
from breezy.bzr import inventory |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
24 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
25 |
|
26 |
||
|
2338.4.3
by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations. |
27 |
class TestRevert(TestCaseWithWorkingTree): |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
28 |
|
29 |
def test_dangling_id(self): |
|
30 |
wt = self.make_branch_and_tree('b1') |
|
31 |
wt.lock_tree_write() |
|
32 |
self.addCleanup(wt.unlock) |
|
|
6825.5.1
by Jelmer Vernooij
Implement Tree.all_versioned_paths. |
33 |
self.assertEqual(len(list(wt.all_versioned_paths())), 1) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
34 |
with open('b1/a', 'wb') as f: |
35 |
f.write(b'a test\n') |
|
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
36 |
wt.add('a') |
|
6825.5.1
by Jelmer Vernooij
Implement Tree.all_versioned_paths. |
37 |
self.assertEqual(len(list(wt.all_versioned_paths())), 2) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
38 |
wt.flush() # workaround revert doing wt._write_inventory for now. |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
39 |
os.unlink('b1/a') |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
40 |
wt.revert() |
|
6825.5.1
by Jelmer Vernooij
Implement Tree.all_versioned_paths. |
41 |
self.assertEqual(len(list(wt.all_versioned_paths())), 1) |
|
2338.4.2
by Marien Zwart
Move the workingtree-related inventory tests to a separate file. |
42 |
|
43 |
||
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
44 |
class TestApplyInventoryDelta(TestCaseWithWorkingTree): |
45 |
||
|
5858.3.3
by Jelmer Vernooij
Skip tests early, before creating a tree. |
46 |
def setUp(self): |
47 |
super(TestApplyInventoryDelta, self).setUp() |
|
48 |
if not self.bzrdir_format.repository_format.supports_full_versioned_files: |
|
49 |
raise tests.TestNotApplicable( |
|
50 |
"format does not support inventory deltas") |
|
51 |
||
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
52 |
def test_add(self): |
53 |
wt = self.make_branch_and_tree('.') |
|
54 |
wt.lock_write() |
|
55 |
self.addCleanup(wt.unlock) |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
56 |
root_id = wt.path2id('') |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
57 |
wt.apply_inventory_delta([(None, 'bar/foo', b'foo-id', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
58 |
inventory.InventoryFile(b'foo-id', 'foo', parent_id=b'bar-id')), |
59 |
(None, 'bar', b'bar-id', inventory.InventoryDirectory(b'bar-id', |
|
60 |
'bar', parent_id=root_id))]) |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
61 |
self.assertEqual('bar/foo', wt.id2path(b'foo-id')) |
62 |
self.assertEqual('bar', wt.id2path(b'bar-id')) |
|
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
63 |
|
64 |
def test_remove(self): |
|
65 |
wt = self.make_branch_and_tree('.') |
|
66 |
wt.lock_write() |
|
67 |
self.addCleanup(wt.unlock) |
|
68 |
self.build_tree(['foo/', 'foo/bar']) |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
69 |
wt.add(['foo', 'foo/bar'], [b'foo-id', b'bar-id']) |
70 |
wt.apply_inventory_delta([('foo', None, b'foo-id', None), |
|
71 |
('foo/bar', None, b'bar-id', None)]) |
|
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
72 |
self.assertFalse(wt.is_versioned('foo')) |
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
73 |
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
74 |
def test_rename_dir_with_children(self): |
75 |
wt = self.make_branch_and_tree('.') |
|
76 |
wt.lock_write() |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
77 |
root_id = wt.path2id('') |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
78 |
self.addCleanup(wt.unlock) |
79 |
self.build_tree(['foo/', 'foo/bar']) |
|
80 |
wt.add(['foo', 'foo/bar'], |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
81 |
[b'foo-id', b'bar-id']) |
82 |
wt.apply_inventory_delta([('foo', 'baz', b'foo-id', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
83 |
inventory.InventoryDirectory(b'foo-id', 'baz', root_id))]) |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
84 |
# foo/bar should have been followed the rename of its parent to baz/bar
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
85 |
self.assertEqual('baz', wt.id2path(b'foo-id')) |
86 |
self.assertEqual('baz/bar', wt.id2path(b'bar-id')) |
|
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
87 |
|
88 |
def test_rename_dir_with_children_with_children(self): |
|
89 |
wt = self.make_branch_and_tree('.') |
|
90 |
wt.lock_write() |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
91 |
root_id = wt.path2id('') |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
92 |
self.addCleanup(wt.unlock) |
93 |
self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz']) |
|
94 |
wt.add(['foo', 'foo/bar', 'foo/bar/baz'], |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
95 |
[b'foo-id', b'bar-id', b'baz-id']) |
96 |
wt.apply_inventory_delta([('foo', 'quux', b'foo-id', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
97 |
inventory.InventoryDirectory(b'foo-id', 'quux', root_id))]) |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
98 |
# foo/bar/baz should have been followed the rename of its parent's
|
99 |
# parent to quux/bar/baz
|
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
100 |
self.assertEqual('quux/bar/baz', wt.id2path(b'baz-id')) |
|
2865.1.1
by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit. |
101 |
|
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
102 |
def test_rename_file(self): |
103 |
wt = self.make_branch_and_tree('.') |
|
104 |
wt.lock_write() |
|
105 |
self.addCleanup(wt.unlock) |
|
106 |
self.build_tree(['foo/', 'foo/bar', 'baz/']) |
|
107 |
wt.add(['foo', 'foo/bar', 'baz'], |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
108 |
[b'foo-id', b'bar-id', b'baz-id']) |
109 |
wt.apply_inventory_delta([('foo/bar', 'baz/bar', b'bar-id', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
110 |
inventory.InventoryFile(b'bar-id', 'bar', b'baz-id'))]) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
111 |
self.assertEqual('baz/bar', wt.id2path(b'bar-id')) |
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
112 |
|
113 |
def test_rename_swap(self): |
|
114 |
"""Test the swap-names edge case. |
|
115 |
||
116 |
foo and bar should swap names, but retain their children. If this
|
|
117 |
works, any simpler rename ought to work.
|
|
118 |
"""
|
|
119 |
wt = self.make_branch_and_tree('.') |
|
120 |
wt.lock_write() |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
121 |
root_id = wt.path2id('') |
|
2376.2.1
by Aaron Bentley
Implement MutableTree.apply_inventory_delta |
122 |
self.addCleanup(wt.unlock) |
123 |
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux']) |
|
124 |
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'], |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
125 |
[b'foo-id', b'bar-id', b'baz-id', b'qux-id']) |
126 |
wt.apply_inventory_delta([('foo', 'baz', b'foo-id', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
127 |
inventory.InventoryDirectory(b'foo-id', 'baz', root_id)), |
128 |
('baz', 'foo', b'baz-id', |
|
129 |
inventory.InventoryDirectory(b'baz-id', 'foo', root_id))]) |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
130 |
self.assertEqual('baz/bar', wt.id2path(b'bar-id')) |
131 |
self.assertEqual('foo/qux', wt.id2path(b'qux-id')) |
|
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
132 |
|
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
133 |
def test_child_rename_ordering(self): |
134 |
"""Test the rename-parent, move child edge case. |
|
135 |
||
136 |
(A naive implementation may move the parent first, and then be
|
|
137 |
unable to find the child.)
|
|
138 |
"""
|
|
139 |
wt = self.make_branch_and_tree('.') |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
140 |
root_id = wt.path2id('') |
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
141 |
self.build_tree(['dir/', 'dir/child', 'other/']) |
142 |
wt.add(['dir', 'dir/child', 'other'], |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
143 |
[b'dir-id', b'child-id', b'other-id']) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
144 |
# this delta moves dir-id to dir2 and reparents
|
|
2865.1.3
by Robert Collins
Review feedback. |
145 |
# child-id to a parent of other-id
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
146 |
wt.apply_inventory_delta([('dir', 'dir2', b'dir-id', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
147 |
inventory.InventoryDirectory(b'dir-id', 'dir2', root_id)), |
148 |
('dir/child', 'other/child', b'child-id', |
|
149 |
inventory.InventoryFile(b'child-id', 'child', b'other-id'))]) |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
150 |
self.assertEqual('dir2', wt.id2path(b'dir-id')) |
151 |
self.assertEqual('other/child', wt.id2path(b'child-id')) |
|
|
2376.2.7
by Aaron Bentley
Add another test case (suggested by John Meinel) |
152 |
|
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
153 |
def test_replace_root(self): |
154 |
wt = self.make_branch_and_tree('.') |
|
155 |
wt.lock_write() |
|
156 |
self.addCleanup(wt.unlock) |
|
157 |
||
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
158 |
root_id = wt.path2id('') |
|
2376.2.3
by Aaron Bentley
Fix root replacement for apply_inventory_delta |
159 |
wt.apply_inventory_delta([('', None, root_id, None), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
160 |
(None, '', b'root-id', |
161 |
inventory.InventoryDirectory(b'root-id', '', None))]) |
|
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
162 |
|
163 |
||
164 |
class TestTreeReference(TestCaseWithWorkingTree): |
|
165 |
||
166 |
def test_tree_reference_matches_inv(self): |
|
|
5858.3.2
by Jelmer Vernooij
Fix spacing. |
167 |
base = self.make_branch_and_tree('base') |
|
5858.3.1
by Jelmer Vernooij
Raise TestNotApplicable for things that don't have an inventory delta. |
168 |
if base.branch.repository._format.supports_full_versioned_files: |
169 |
raise tests.TestNotApplicable( |
|
170 |
"format does not support inventory deltas") |
|
|
5786.1.6
by John Arbash Meinel
Clean up some of the old tests that I had updated. |
171 |
if not base.supports_tree_reference(): |
172 |
raise tests.TestNotApplicable("wt doesn't support nested trees") |
|
|
6926.2.8
by Jelmer Vernooij
Fix some more tests. |
173 |
if base.has_versioned_directories(): |
174 |
# We add it as a directory, but it becomes a tree-reference
|
|
175 |
base.add(['subdir'], [None], ['directory']) |
|
176 |
subdir = self.make_branch_and_tree('base/subdir') |
|
177 |
else: |
|
178 |
subdir = self.make_branch_and_tree('base/subdir') |
|
179 |
subdir.commit('') |
|
180 |
# We add it as a directory, but it becomes a tree-reference
|
|
181 |
base.add(['subdir'], [None], ['tree-reference']) |
|
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
182 |
self.addCleanup(base.lock_read().unlock) |
|
5786.1.6
by John Arbash Meinel
Clean up some of the old tests that I had updated. |
183 |
# Note: we aren't strict about ie.kind being 'directory' here, what we
|
184 |
# are strict about is that wt.inventory should match
|
|
185 |
# wt.current_dirstate()'s idea about what files are where.
|
|
|
6885.6.1
by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir. |
186 |
path, ie = next(base.iter_entries_by_dir(specific_files=['subdir'])) |
|
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
187 |
self.assertEqual('subdir', path) |
188 |
self.assertEqual('tree-reference', ie.kind) |