350
350
def test_iter_all_entries_simple(self):
351
351
index = self.make_index(nodes=[(('name', ), 'data', ())])
352
self.assertEqual([(('name', ), 'data')],
352
self.assertEqual([(index, ('name', ), 'data')],
353
353
list(index.iter_all_entries()))
355
355
def test_iter_all_entries_simple_2_elements(self):
356
356
index = self.make_index(key_elements=2,
357
357
nodes=[(('name', 'surname'), 'data', ())])
358
self.assertEqual([(('name', 'surname'), 'data')],
358
self.assertEqual([(index, ('name', 'surname'), 'data')],
359
359
list(index.iter_all_entries()))
361
361
def test_iter_all_entries_references_resolved(self):
362
362
index = self.make_index(1, nodes=[
363
363
(('name', ), 'data', ([('ref', )], )),
364
364
(('ref', ), 'refdata', ([], ))])
365
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
366
(('ref', ), 'refdata', ((), ))]),
365
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),)),
366
(index, ('ref', ), 'refdata', ((), ))]),
367
367
set(index.iter_all_entries()))
369
369
def test_iteration_absent_skipped(self):
370
370
index = self.make_index(1, nodes=[
371
371
(('name', ), 'data', ([('ref', )], ))])
372
self.assertEqual(set([(('name', ), 'data', ((('ref',),),))]),
372
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),))]),
373
373
set(index.iter_all_entries()))
374
self.assertEqual(set([(('name', ), 'data', ((('ref',),),))]),
374
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),))]),
375
375
set(index.iter_entries([('name', )])))
376
376
self.assertEqual([], list(index.iter_entries([('ref', )])))
378
378
def test_iteration_absent_skipped_2_element_keys(self):
379
379
index = self.make_index(1, key_elements=2, nodes=[
380
380
(('name', 'fin'), 'data', ([('ref', 'erence')], ))])
381
self.assertEqual(set([(('name', 'fin'), 'data', ((('ref', 'erence'),),))]),
381
self.assertEqual(set([(index, ('name', 'fin'), 'data', ((('ref', 'erence'),),))]),
382
382
set(index.iter_all_entries()))
383
self.assertEqual(set([(('name', 'fin'), 'data', ((('ref', 'erence'),),))]),
383
self.assertEqual(set([(index, ('name', 'fin'), 'data', ((('ref', 'erence'),),))]),
384
384
set(index.iter_entries([('name', 'fin')])))
385
385
self.assertEqual([], list(index.iter_entries([('ref', 'erence')])))
388
388
index = self.make_index(1, nodes=[
389
389
(('name', ), 'data', ([('ref', )], )),
390
390
(('ref', ), 'refdata', ([], ))])
391
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
392
(('ref', ), 'refdata', ((), ))]),
391
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),)),
392
(index, ('ref', ), 'refdata', ((), ))]),
393
393
set(index.iter_entries([('name', ), ('ref', )])))
395
395
def test_iter_nothing_empty(self):
419
419
index = self.make_index( nodes=[
420
420
(('name', ), 'data', ()),
421
421
(('ref', ), 'refdata', ())])
422
self.assertEqual(set([(('name', ), 'data'),
423
(('ref', ), 'refdata')]),
422
self.assertEqual(set([(index, ('name', ), 'data'),
423
(index, ('ref', ), 'refdata')]),
424
424
set(index.iter_entries_prefix([('name', ), ('ref', )])))
426
426
def test_iter_key_prefix_1_key_element_refs(self):
427
427
index = self.make_index(1, nodes=[
428
428
(('name', ), 'data', ([('ref', )], )),
429
429
(('ref', ), 'refdata', ([], ))])
430
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
431
(('ref', ), 'refdata', ((), ))]),
430
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),)),
431
(index, ('ref', ), 'refdata', ((), ))]),
432
432
set(index.iter_entries_prefix([('name', ), ('ref', )])))
434
434
def test_iter_key_prefix_2_key_element_no_refs(self):
436
436
(('name', 'fin1'), 'data', ()),
437
437
(('name', 'fin2'), 'beta', ()),
438
438
(('ref', 'erence'), 'refdata', ())])
439
self.assertEqual(set([(('name', 'fin1'), 'data'),
440
(('ref', 'erence'), 'refdata')]),
439
self.assertEqual(set([(index, ('name', 'fin1'), 'data'),
440
(index, ('ref', 'erence'), 'refdata')]),
441
441
set(index.iter_entries_prefix([('name', 'fin1'), ('ref', 'erence')])))
442
self.assertEqual(set([(('name', 'fin1'), 'data'),
443
(('name', 'fin2'), 'beta')]),
442
self.assertEqual(set([(index, ('name', 'fin1'), 'data'),
443
(index, ('name', 'fin2'), 'beta')]),
444
444
set(index.iter_entries_prefix([('name', None)])))
446
446
def test_iter_key_prefix_2_key_element_refs(self):
448
448
(('name', 'fin1'), 'data', ([('ref', 'erence')], )),
449
449
(('name', 'fin2'), 'beta', ([], )),
450
450
(('ref', 'erence'), 'refdata', ([], ))])
451
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
452
(('ref', 'erence'), 'refdata', ((), ))]),
451
self.assertEqual(set([(index, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
452
(index, ('ref', 'erence'), 'refdata', ((), ))]),
453
453
set(index.iter_entries_prefix([('name', 'fin1'), ('ref', 'erence')])))
454
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
455
(('name', 'fin2'), 'beta', ((), ))]),
454
self.assertEqual(set([(index, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
455
(index, ('name', 'fin2'), 'beta', ((), ))]),
456
456
set(index.iter_entries_prefix([('name', None)])))
458
458
def test_validate_bad_index_errors(self):
529
529
def test_iter_all_entries_simple(self):
530
530
index1 = self.make_index('name', nodes=[(('name', ), 'data', ())])
531
531
index = CombinedGraphIndex([index1])
532
self.assertEqual([(('name', ), 'data')],
532
self.assertEqual([(index1, ('name', ), 'data')],
533
533
list(index.iter_all_entries()))
535
535
def test_iter_all_entries_two_indices(self):
536
536
index1 = self.make_index('name1', nodes=[(('name', ), 'data', ())])
537
537
index2 = self.make_index('name2', nodes=[(('2', ), '', ())])
538
538
index = CombinedGraphIndex([index1, index2])
539
self.assertEqual([(('name', ), 'data'),
539
self.assertEqual([(index1, ('name', ), 'data'),
540
(index2, ('2', ), '')],
541
541
list(index.iter_all_entries()))
543
543
def test_iter_entries_two_indices_dup_key(self):
544
544
index1 = self.make_index('name1', nodes=[(('name', ), 'data', ())])
545
545
index2 = self.make_index('name2', nodes=[(('name', ), 'data', ())])
546
546
index = CombinedGraphIndex([index1, index2])
547
self.assertEqual([(('name', ), 'data')],
547
self.assertEqual([(index1, ('name', ), 'data')],
548
548
list(index.iter_entries([('name', )])))
550
550
def test_iter_all_entries_two_indices_dup_key(self):
551
551
index1 = self.make_index('name1', nodes=[(('name', ), 'data', ())])
552
552
index2 = self.make_index('name2', nodes=[(('name', ), 'data', ())])
553
553
index = CombinedGraphIndex([index1, index2])
554
self.assertEqual([(('name', ), 'data')],
554
self.assertEqual([(index1, ('name', ), 'data')],
555
555
list(index.iter_all_entries()))
557
557
def test_iter_key_prefix_2_key_element_refs(self):
561
561
(('name', 'fin2'), 'beta', ([], )),
562
562
(('ref', 'erence'), 'refdata', ([], ))])
563
563
index = CombinedGraphIndex([index1, index2])
564
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
565
(('ref', 'erence'), 'refdata', ((), ))]),
564
self.assertEqual(set([(index1, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
565
(index2, ('ref', 'erence'), 'refdata', ((), ))]),
566
566
set(index.iter_entries_prefix([('name', 'fin1'), ('ref', 'erence')])))
567
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
568
(('name', 'fin2'), 'beta', ((), ))]),
567
self.assertEqual(set([(index1, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
568
(index2, ('name', 'fin2'), 'beta', ((), ))]),
569
569
set(index.iter_entries_prefix([('name', None)])))
571
571
def test_iter_nothing_empty(self):
583
583
index2 = self.make_index('2', 1, nodes=[
584
584
(('ref', ), 'refdata', ((), ))])
585
585
index = CombinedGraphIndex([index1, index2])
586
self.assertEqual(set([(('name', ), 'data', ((('ref', ), ), )),
587
(('ref', ), 'refdata', ((), ))]),
586
self.assertEqual(set([(index1, ('name', ), 'data', ((('ref', ), ), )),
587
(index2, ('ref', ), 'refdata', ((), ))]),
588
588
set(index.iter_entries([('name', ), ('ref', )])))
590
590
def test_iter_all_keys_dup_entry(self):
594
594
index2 = self.make_index('2', 1, nodes=[
595
595
(('ref', ), 'refdata', ([], ))])
596
596
index = CombinedGraphIndex([index1, index2])
597
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
598
(('ref', ), 'refdata', ((), ))]),
597
self.assertEqual(set([(index1, ('name', ), 'data', ((('ref',),),)),
598
(index1, ('ref', ), 'refdata', ((), ))]),
599
599
set(index.iter_entries([('name', ), ('ref', )])))
601
601
def test_iter_missing_entry_empty(self):
617
617
index1 = self.make_index('1', nodes=[(('key', ), '', ())])
618
618
index2 = self.make_index('2', nodes=[])
619
619
index = CombinedGraphIndex([index1, index2])
620
self.assertEqual([(('key', ), '')],
620
self.assertEqual([(index1, ('key', ), '')],
621
621
list(index.iter_entries([('key', )])))
622
622
# and in the other direction
623
623
index = CombinedGraphIndex([index2, index1])
624
self.assertEqual([(('key', ), '')],
624
self.assertEqual([(index1, ('key', ), '')],
625
625
list(index.iter_entries([('key', )])))
627
627
def test_validate_bad_child_index_errors(self):
658
658
index.add_nodes([(('name', ), 'data', ([],))])
659
659
index.add_nodes([(('name2', ), '', ([],)), (('name3', ), '', ([('r', )],))])
660
660
self.assertEqual(set([
661
(('name', ), 'data', ((),)),
662
(('name2', ), '', ((),)),
663
(('name3', ), '', ((('r', ), ), )),
661
(index, ('name', ), 'data', ((),)),
662
(index, ('name2', ), '', ((),)),
663
(index, ('name3', ), '', ((('r', ), ), )),
664
664
]), set(index.iter_all_entries()))
666
666
def test_iter_all_entries_empty(self):
670
670
def test_iter_all_entries_simple(self):
671
671
index = self.make_index(nodes=[(('name', ), 'data')])
672
self.assertEqual([(('name', ), 'data')],
672
self.assertEqual([(index, ('name', ), 'data')],
673
673
list(index.iter_all_entries()))
675
675
def test_iter_all_entries_references(self):
676
676
index = self.make_index(1, nodes=[
677
677
(('name', ), 'data', ([('ref', )], )),
678
678
(('ref', ), 'refdata', ([], ))])
679
self.assertEqual(set([(('name', ), 'data', ((('ref', ),),)),
680
(('ref', ), 'refdata', ((), ))]),
679
self.assertEqual(set([(index, ('name', ), 'data', ((('ref', ),),)),
680
(index, ('ref', ), 'refdata', ((), ))]),
681
681
set(index.iter_all_entries()))
683
683
def test_iteration_absent_skipped(self):
684
684
index = self.make_index(1, nodes=[
685
685
(('name', ), 'data', ([('ref', )], ))])
686
self.assertEqual(set([(('name', ), 'data', ((('ref',),),))]),
686
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),))]),
687
687
set(index.iter_all_entries()))
688
self.assertEqual(set([(('name', ), 'data', ((('ref',),),))]),
688
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),))]),
689
689
set(index.iter_entries([('name', )])))
690
690
self.assertEqual([], list(index.iter_entries([('ref', )])))
693
693
index = self.make_index(1, nodes=[
694
694
(('name', ), 'data', ([('ref', )], )),
695
695
(('ref', ), 'refdata', ([], ))])
696
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
697
(('ref', ), 'refdata', ((), ))]),
696
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),)),
697
(index, ('ref', ), 'refdata', ((), ))]),
698
698
set(index.iter_entries([('name', ), ('ref', )])))
700
700
def test_iter_key_prefix_1_key_element_no_refs(self):
701
701
index = self.make_index( nodes=[
702
702
(('name', ), 'data'),
703
703
(('ref', ), 'refdata')])
704
self.assertEqual(set([(('name', ), 'data'),
705
(('ref', ), 'refdata')]),
704
self.assertEqual(set([(index, ('name', ), 'data'),
705
(index, ('ref', ), 'refdata')]),
706
706
set(index.iter_entries_prefix([('name', ), ('ref', )])))
708
708
def test_iter_key_prefix_1_key_element_refs(self):
709
709
index = self.make_index(1, nodes=[
710
710
(('name', ), 'data', ([('ref', )], )),
711
711
(('ref', ), 'refdata', ([], ))])
712
self.assertEqual(set([(('name', ), 'data', ((('ref',),),)),
713
(('ref', ), 'refdata', ((), ))]),
712
self.assertEqual(set([(index, ('name', ), 'data', ((('ref',),),)),
713
(index, ('ref', ), 'refdata', ((), ))]),
714
714
set(index.iter_entries_prefix([('name', ), ('ref', )])))
716
716
def test_iter_key_prefix_2_key_element_no_refs(self):
718
718
(('name', 'fin1'), 'data'),
719
719
(('name', 'fin2'), 'beta'),
720
720
(('ref', 'erence'), 'refdata')])
721
self.assertEqual(set([(('name', 'fin1'), 'data'),
722
(('ref', 'erence'), 'refdata')]),
721
self.assertEqual(set([(index, ('name', 'fin1'), 'data'),
722
(index, ('ref', 'erence'), 'refdata')]),
723
723
set(index.iter_entries_prefix([('name', 'fin1'), ('ref', 'erence')])))
724
self.assertEqual(set([(('name', 'fin1'), 'data'),
725
(('name', 'fin2'), 'beta')]),
724
self.assertEqual(set([(index, ('name', 'fin1'), 'data'),
725
(index, ('name', 'fin2'), 'beta')]),
726
726
set(index.iter_entries_prefix([('name', None)])))
728
728
def test_iter_key_prefix_2_key_element_refs(self):
730
730
(('name', 'fin1'), 'data', ([('ref', 'erence')], )),
731
731
(('name', 'fin2'), 'beta', ([], )),
732
732
(('ref', 'erence'), 'refdata', ([], ))])
733
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
734
(('ref', 'erence'), 'refdata', ((), ))]),
733
self.assertEqual(set([(index, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
734
(index, ('ref', 'erence'), 'refdata', ((), ))]),
735
735
set(index.iter_entries_prefix([('name', 'fin1'), ('ref', 'erence')])))
736
self.assertEqual(set([(('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
737
(('name', 'fin2'), 'beta', ((), ))]),
736
self.assertEqual(set([(index, ('name', 'fin1'), 'data', ((('ref', 'erence'),),)),
737
(index, ('name', 'fin2'), 'beta', ((), ))]),
738
738
set(index.iter_entries_prefix([('name', None)])))
740
740
def test_iter_nothing_empty(self):
780
780
(('key2',), 'value2', ((),)),
782
782
self.assertEqual(set([
783
(('prefix', 'key2'), 'value2', ((),)),
784
(('prefix', 'key'), 'value', ((('prefix', 'ref'),),))
783
(index, ('prefix', 'key2'), 'value2', ((),)),
784
(index, ('prefix', 'key'), 'value', ((('prefix', 'ref'),),))
786
786
set(index.iter_all_entries()))
803
803
(('notprefix', 'key1'), 'data', ((), )),
804
804
(('prefix', 'key1'), 'data1', ((), )),
805
805
(('prefix', 'key2'), 'data2', ((('prefix', 'key1'),),))])
806
self.assertEqual(set([(('key1', ), 'data1', ((),)),
807
(('key2', ), 'data2', ((('key1',),),))]),
806
self.assertEqual(set([(index, ('key1', ), 'data1', ((),)),
807
(index, ('key2', ), 'data2', ((('key1',),),))]),
808
808
set(adapter.iter_all_entries()))
810
810
def test_iter_entries(self):
813
813
(('prefix', 'key1'), 'data1', ((), )),
814
814
(('prefix', 'key2'), 'data2', ((('prefix', 'key1'),),))])
815
815
# ask for many - get all
816
self.assertEqual(set([(('key1', ), 'data1', ((),)),
817
(('key2', ), 'data2', ((('key1', ),),))]),
816
self.assertEqual(set([(index, ('key1', ), 'data1', ((),)),
817
(index, ('key2', ), 'data2', ((('key1', ),),))]),
818
818
set(adapter.iter_entries([('key1', ), ('key2', )])))
819
819
# ask for one, get one
820
self.assertEqual(set([(('key1', ), 'data1', ((),))]),
820
self.assertEqual(set([(index, ('key1', ), 'data1', ((),))]),
821
821
set(adapter.iter_entries([('key1', )])))
822
822
# ask for missing, get none
823
823
self.assertEqual(set(),
829
829
(('prefix', 'prefix2', 'key1'), 'data1', ((), )),
830
830
(('prefix', 'prefix2', 'key2'), 'data2', ((('prefix', 'prefix2', 'key1'),),))])
831
831
# ask for a prefix, get the results for just that prefix, adjusted.
832
self.assertEqual(set([(('prefix2', 'key1', ), 'data1', ((),)),
833
(('prefix2', 'key2', ), 'data2', ((('prefix2', 'key1', ),),))]),
832
self.assertEqual(set([(index, ('prefix2', 'key1', ), 'data1', ((),)),
833
(index, ('prefix2', 'key2', ), 'data2', ((('prefix2', 'key1', ),),))]),
834
834
set(adapter.iter_entries_prefix([('prefix2', None)])))
836
836
def test_validate(self):