40
class TestInventoryBasics(TestCase):
41
# Most of these were moved the rather old bzrlib.tests.test_inv module
40
class TestInventory(TestCase):
43
42
def make_inventory(self, root_id):
44
43
return self.inventory_class(root_id=root_id)
46
class TestInventoryUpdates(TestInventory):
46
48
def test_creation_from_root_id(self):
47
49
# iff a root id is passed to the constructor, a root directory is made
48
50
inv = self.make_inventory(root_id='tree-root')
88
90
self.assertEquals('someroot', inv2.root.file_id)
89
91
self.assertEquals('therev', inv2.root.revision)
91
def test_is_root(self):
92
"""Ensure our root-checking code is accurate."""
93
inv = self.make_inventory('TREE_ROOT')
94
self.assertTrue(inv.is_root('TREE_ROOT'))
95
self.assertFalse(inv.is_root('booga'))
96
inv.root.file_id = 'booga'
97
self.assertFalse(inv.is_root('TREE_ROOT'))
98
self.assertTrue(inv.is_root('booga'))
99
# works properly even if no root is set
101
self.assertFalse(inv.is_root('TREE_ROOT'))
102
self.assertFalse(inv.is_root('booga'))
104
93
def test_create_tree_reference(self):
105
94
inv = self.make_inventory('tree-root-123')
106
95
inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
117
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'))
119
171
def test_ids(self):
120
172
"""Test detection of files within selected directories."""
121
173
inv = self.make_inventory(ROOT_ID)
231
283
('src/bye.c', 'bye-id'),
232
284
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
233
285
specific_file_ids=('bye-id',), yield_parents=True)])
235
def test_add_recursive(self):
236
parent = InventoryDirectory('src-id', 'src', 'tree-root')
237
child = InventoryFile('hello-id', 'hello.c', 'src-id')
238
parent.children[child.file_id] = child
239
inv = self.make_inventory('tree-root')
241
self.assertEqual('src/hello.c', inv.id2path('hello-id'))