35
35
from bzrlib.tests import (
37
multiply_tests_from_modules,
41
class TestInventoryBasics(TestCase):
42
# Most of these were moved the rather old bzrlib.tests.test_inv module
40
class TestInventory(TestCase):
44
42
def make_inventory(self, root_id):
45
43
return self.inventory_class(root_id=root_id)
46
class TestInventoryUpdates(TestInventory):
47
48
def test_creation_from_root_id(self):
48
49
# iff a root id is passed to the constructor, a root directory is made
49
50
inv = self.make_inventory(root_id='tree-root')
89
90
self.assertEquals('someroot', inv2.root.file_id)
90
91
self.assertEquals('therev', inv2.root.revision)
92
def test_is_root(self):
93
"""Ensure our root-checking code is accurate."""
94
inv = self.make_inventory('TREE_ROOT')
95
self.assertTrue(inv.is_root('TREE_ROOT'))
96
self.assertFalse(inv.is_root('booga'))
97
inv.root.file_id = 'booga'
98
self.assertFalse(inv.is_root('TREE_ROOT'))
99
self.assertTrue(inv.is_root('booga'))
100
# works properly even if no root is set
102
self.assertFalse(inv.is_root('TREE_ROOT'))
103
self.assertFalse(inv.is_root('booga'))
105
93
def test_create_tree_reference(self):
106
94
inv = self.make_inventory('tree-root-123')
107
95
inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
118
106
self.fail('BzrError not raised')
108
def test_add_recursive(self):
109
parent = InventoryDirectory('src-id', 'src', 'tree-root')
110
child = InventoryFile('hello-id', 'hello.c', 'src-id')
111
parent.children[child.file_id] = child
112
inv = self.make_inventory('tree-root')
114
self.assertEqual('src/hello.c', inv.id2path('hello-id'))
117
class TestInventoryApplyDelta(TestInventory):
119
def test_apply_delta_add(self):
120
inv = self.make_inventory('tree-root')
122
(None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
124
self.assertEqual('a', inv.id2path('a-id'))
126
def test_apply_delta_delete(self):
127
inv = self.make_inventory('tree-root')
129
(None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
131
self.assertEqual('a', inv.id2path('a-id'))
133
inv.apply_delta([("a", None, "a-id", a_ie)])
134
self.assertRaises(errors.NoSuchId, inv.id2path, 'a-id')
136
def test_apply_delta_rename(self):
137
inv = self.make_inventory('tree-root')
139
(None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
141
self.assertEqual('a', inv.id2path('a-id'))
143
b_ie = InventoryFile(a_ie.file_id, "b", a_ie.parent_id)
144
inv.apply_delta([("a", "b", "a-id", b_ie)])
145
self.assertEqual("b", inv.id2path('a-id'))
147
def test_apply_delta_illegal(self):
148
# A file-id cannot appear in a delta more than once
149
inv = self.make_inventory('tree-root')
150
self.assertRaises(AssertionError, inv.apply_delta, [
151
("a", "a", "id-1", InventoryFile('id-1', 'a', 'tree-root')),
152
("a", "b", "id-1", InventoryFile('id-1', 'b', 'tree-root')),
156
class TestInventoryReads(TestInventory):
158
def test_is_root(self):
159
"""Ensure our root-checking code is accurate."""
160
inv = self.make_inventory('TREE_ROOT')
161
self.assertTrue(inv.is_root('TREE_ROOT'))
162
self.assertFalse(inv.is_root('booga'))
163
inv.root.file_id = 'booga'
164
self.assertFalse(inv.is_root('TREE_ROOT'))
165
self.assertTrue(inv.is_root('booga'))
166
# works properly even if no root is set
168
self.assertFalse(inv.is_root('TREE_ROOT'))
169
self.assertFalse(inv.is_root('booga'))
120
171
def test_ids(self):
121
172
"""Test detection of files within selected directories."""
122
173
inv = self.make_inventory(ROOT_ID)
232
283
('src/bye.c', 'bye-id'),
233
284
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
234
285
specific_file_ids=('bye-id',), yield_parents=True)])
236
def test_add_recursive(self):
237
parent = InventoryDirectory('src-id', 'src', 'tree-root')
238
child = InventoryFile('hello-id', 'hello.c', 'src-id')
239
parent.children[child.file_id] = child
240
inv = self.make_inventory('tree-root')
242
self.assertEqual('src/hello.c', inv.id2path('hello-id'))