312
312
def test_validate_no_refs_content(self):
313
313
index = self.make_index(nodes=[('key', (), 'value')])
317
class TestCombinedGraphIndex(TestCaseWithMemoryTransport):
319
def make_index(self, name, ref_lists=0, nodes=[]):
320
builder = GraphIndexBuilder(ref_lists)
321
for node, references, value in nodes:
322
builder.add_node(node, references, value)
323
stream = builder.finish()
324
trans = self.get_transport()
325
trans.put_file(name, stream)
326
return GraphIndex(trans, name)
328
def test_open_missing_index_no_error(self):
329
trans = self.get_transport()
330
index1 = GraphIndex(trans, 'missing')
331
index = CombinedGraphIndex([index1])
333
def test_iter_all_entries_empty(self):
334
index = CombinedGraphIndex([])
335
self.assertEqual([], list(index.iter_all_entries()))
337
def test_iter_all_entries_children_empty(self):
338
index1 = self.make_index('name')
339
index = CombinedGraphIndex([index1])
340
self.assertEqual([], list(index.iter_all_entries()))
342
def test_iter_all_entries_simple(self):
343
index1 = self.make_index('name', nodes=[('name', (), 'data')])
344
index = CombinedGraphIndex([index1])
345
self.assertEqual([('name', (), 'data')],
346
list(index.iter_all_entries()))
348
def test_iter_all_entries_two_indices(self):
349
index1 = self.make_index('name1', nodes=[('name', (), 'data')])
350
index2 = self.make_index('name2', nodes=[('2', (), '')])
351
index = CombinedGraphIndex([index1, index2])
352
self.assertEqual([('name', (), 'data'),
354
list(index.iter_all_entries()))
356
def test_iter_all_entries_two_indices_dup_key(self):
357
index1 = self.make_index('name1', nodes=[('name', (), 'data')])
358
index2 = self.make_index('name2', nodes=[('name', (), 'data')])
359
index = CombinedGraphIndex([index1, index2])
360
self.assertEqual([('name', (), 'data')],
361
list(index.iter_all_entries()))
363
def test_iter_nothing_empty(self):
364
index = CombinedGraphIndex([])
365
self.assertEqual([], list(index.iter_entries([])))
367
def test_iter_nothing_children_empty(self):
368
index1 = self.make_index('name')
369
index = CombinedGraphIndex([index1])
370
self.assertEqual([], list(index.iter_entries([])))
372
def test_iter_all_keys(self):
373
index1 = self.make_index('1', 1, nodes=[
374
('name', (['ref'], ), 'data')])
375
index2 = self.make_index('2', 1, nodes=[
376
('ref', ([], ), 'refdata')])
377
index = CombinedGraphIndex([index1, index2])
378
self.assertEqual(set([('name', (('ref',),), 'data'),
379
('ref', ((), ), 'refdata')]),
380
set(index.iter_entries(['name', 'ref'])))
382
def test_iter_all_keys_dup_entry(self):
383
index1 = self.make_index('1', 1, nodes=[
384
('name', (['ref'], ), 'data'),
385
('ref', ([], ), 'refdata')])
386
index2 = self.make_index('2', 1, nodes=[
387
('ref', ([], ), 'refdata')])
388
index = CombinedGraphIndex([index1, index2])
389
self.assertEqual(set([('name', (('ref',),), 'data'),
390
('ref', ((), ), 'refdata')]),
391
set(index.iter_entries(['name', 'ref'])))
393
def test_iter_missing_entry_empty(self):
394
index = CombinedGraphIndex([])
395
self.assertRaises(errors.MissingKey, list, index.iter_entries(['a']))
397
def test_iter_missing_entry_one_index(self):
398
index1 = self.make_index('1')
399
index = CombinedGraphIndex([index1])
400
self.assertRaises(errors.MissingKey, list, index.iter_entries(['a']))
402
def test_iter_missing_entry_two_index(self):
403
index1 = self.make_index('1')
404
index2 = self.make_index('2')
405
index = CombinedGraphIndex([index1, index2])
406
self.assertRaises(errors.MissingKey, list, index.iter_entries(['a']))
408
def test_iter_entry_present_one_index_only(self):
409
index1 = self.make_index('1', nodes=[('key', (), '')])
410
index2 = self.make_index('2', nodes=[])
411
index = CombinedGraphIndex([index1, index2])
412
self.assertEqual([('key', (), '')],
413
list(index.iter_entries(['key'])))
414
# and in the other direction
415
index = CombinedGraphIndex([index2, index1])
416
self.assertEqual([('key', (), '')],
417
list(index.iter_entries(['key'])))
419
def test_validate_bad_child_index_errors(self):
420
trans = self.get_transport()
421
trans.put_bytes('name', "not an index\n")
422
index1 = GraphIndex(trans, 'name')
423
index = CombinedGraphIndex([index1])
424
self.assertRaises(errors.BadIndexFormatSignature, index.validate)
426
def test_validate_empty(self):
427
index = CombinedGraphIndex([])