166
166
def assertChangeDescription(self, expected_change, old_ie, new_ie):
167
167
change = InventoryEntry.describe_change(old_ie, new_ie)
168
168
self.assertEqual(expected_change, change)
171
class TestCHKInventory(TestCaseWithTransport):
173
def get_chk_bytes(self):
174
# The eassiest way to get a CHK store is a development3 repository and
175
# then work with the chk_bytes attribute directly.
176
repo = self.make_repository(".", format="development3")
178
self.addCleanup(repo.unlock)
179
repo.start_write_group()
180
self.addCleanup(repo.abort_write_group)
181
return repo.chk_bytes
183
def read_bytes(self, chk_bytes, key):
184
stream = chk_bytes.get_record_stream([key], 'unordered', True)
185
return stream.next().get_bytes_as("fulltext")
187
def test_deserialise_gives_CHKInventory(self):
189
inv.revision_id = "revid"
190
inv.root.revision = "rootrev"
191
chk_bytes = self.get_chk_bytes()
192
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
193
bytes = ''.join(chk_inv.to_lines())
194
new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
195
self.assertEqual("revid", new_inv.revision_id)
196
self.assertEqual("directory", new_inv.root.kind)
197
self.assertEqual(inv.root.file_id, new_inv.root.file_id)
198
self.assertEqual(inv.root.parent_id, new_inv.root.parent_id)
199
self.assertEqual(inv.root.name, new_inv.root.name)
200
self.assertEqual("rootrev", new_inv.root.revision)
202
def test_deserialise_wrong_revid(self):
204
inv.revision_id = "revid"
205
inv.root.revision = "rootrev"
206
chk_bytes = self.get_chk_bytes()
207
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
208
bytes = ''.join(chk_inv.to_lines())
209
self.assertRaises(ValueError, CHKInventory.deserialise, chk_bytes,
212
def test_captures_rev_root_byid(self):
214
inv.revision_id = "foo"
215
inv.root.revision = "bar"
216
chk_bytes = self.get_chk_bytes()
217
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
220
'revision_id: foo\n',
221
'root_id: TREE_ROOT\n',
222
'id_to_entry: sha1:dc696b0cf291ac0d66bdcda3070f755494a586fc\n'
226
def test_directory_children_on_demand(self):
228
inv.revision_id = "revid"
229
inv.root.revision = "rootrev"
230
inv.add(InventoryFile("fileid", "file", inv.root.file_id))
231
inv["fileid"].revision = "filerev"
232
inv["fileid"].executable = True
233
inv["fileid"].text_sha1 = "ffff"
234
inv["fileid"].text_size = 1
235
chk_bytes = self.get_chk_bytes()
236
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
237
bytes = ''.join(chk_inv.to_lines())
238
new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
239
root_entry = new_inv[inv.root.file_id]
240
self.assertEqual(None, root_entry._children)
241
self.assertEqual(['file'], root_entry.children.keys())
242
file_direct = new_inv["fileid"]
243
file_found = root_entry.children['file']
244
self.assertEqual(file_direct.kind, file_found.kind)
245
self.assertEqual(file_direct.file_id, file_found.file_id)
246
self.assertEqual(file_direct.parent_id, file_found.parent_id)
247
self.assertEqual(file_direct.name, file_found.name)
248
self.assertEqual(file_direct.revision, file_found.revision)
249
self.assertEqual(file_direct.text_sha1, file_found.text_sha1)
250
self.assertEqual(file_direct.text_size, file_found.text_size)
251
self.assertEqual(file_direct.executable, file_found.executable)
253
def test___iter__(self):
255
inv.revision_id = "revid"
256
inv.root.revision = "rootrev"
257
inv.add(InventoryFile("fileid", "file", inv.root.file_id))
258
inv["fileid"].revision = "filerev"
259
inv["fileid"].executable = True
260
inv["fileid"].text_sha1 = "ffff"
261
inv["fileid"].text_size = 1
262
chk_bytes = self.get_chk_bytes()
263
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
264
bytes = ''.join(chk_inv.to_lines())
265
new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
266
fileids = list(new_inv.__iter__())
268
self.assertEqual([inv.root.file_id, "fileid"], fileids)
270
def test__len__(self):
272
inv.revision_id = "revid"
273
inv.root.revision = "rootrev"
274
inv.add(InventoryFile("fileid", "file", inv.root.file_id))
275
inv["fileid"].revision = "filerev"
276
inv["fileid"].executable = True
277
inv["fileid"].text_sha1 = "ffff"
278
inv["fileid"].text_size = 1
279
chk_bytes = self.get_chk_bytes()
280
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
281
self.assertEqual(2, len(chk_inv))
283
def test___getitem__(self):
285
inv.revision_id = "revid"
286
inv.root.revision = "rootrev"
287
inv.add(InventoryFile("fileid", "file", inv.root.file_id))
288
inv["fileid"].revision = "filerev"
289
inv["fileid"].executable = True
290
inv["fileid"].text_sha1 = "ffff"
291
inv["fileid"].text_size = 1
292
chk_bytes = self.get_chk_bytes()
293
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
294
bytes = ''.join(chk_inv.to_lines())
295
new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
296
root_entry = new_inv[inv.root.file_id]
297
file_entry = new_inv["fileid"]
298
self.assertEqual("directory", root_entry.kind)
299
self.assertEqual(inv.root.file_id, root_entry.file_id)
300
self.assertEqual(inv.root.parent_id, root_entry.parent_id)
301
self.assertEqual(inv.root.name, root_entry.name)
302
self.assertEqual("rootrev", root_entry.revision)
303
self.assertEqual("file", file_entry.kind)
304
self.assertEqual("fileid", file_entry.file_id)
305
self.assertEqual(inv.root.file_id, file_entry.parent_id)
306
self.assertEqual("file", file_entry.name)
307
self.assertEqual("filerev", file_entry.revision)
308
self.assertEqual("ffff", file_entry.text_sha1)
309
self.assertEqual(1, file_entry.text_size)
310
self.assertEqual(True, file_entry.executable)
312
def test_has_id_true(self):
314
inv.revision_id = "revid"
315
inv.root.revision = "rootrev"
316
inv.add(InventoryFile("fileid", "file", inv.root.file_id))
317
inv["fileid"].revision = "filerev"
318
inv["fileid"].executable = True
319
inv["fileid"].text_sha1 = "ffff"
320
inv["fileid"].text_size = 1
321
chk_bytes = self.get_chk_bytes()
322
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
323
self.assertTrue(chk_inv.has_id('fileid'))
324
self.assertTrue(chk_inv.has_id(inv.root.file_id))
326
def test_has_id_not(self):
328
inv.revision_id = "revid"
329
inv.root.revision = "rootrev"
330
chk_bytes = self.get_chk_bytes()
331
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
332
self.assertFalse(chk_inv.has_id('fileid'))