630
630
text = k.get_text('text-1')
631
631
self.assertEqual(TEXT_1, text)
632
632
self.assertEqual({}, k._data._cache)
635
class TestKnitIndex(KnitTests):
637
def test_add_versions_dictionary_compresses(self):
638
"""Adding versions to the index should update the lookup dict"""
639
knit = self.make_test_knit()
641
idx.add_version('a-1', ['fulltext'], 0, 0, [])
642
self.check_file_contents('test.kndx',
643
'# bzr knit index 8\n'
647
idx.add_versions([('a-2', ['fulltext'], 0, 0, ['a-1']),
648
('a-3', ['fulltext'], 0, 0, ['a-2']),
650
self.check_file_contents('test.kndx',
651
'# bzr knit index 8\n'
653
'a-1 fulltext 0 0 :\n'
654
'a-2 fulltext 0 0 0 :\n'
655
'a-3 fulltext 0 0 1 :'
657
self.assertEqual(['a-1', 'a-2', 'a-3'], idx._history)
658
self.assertEqual({'a-1':('a-1', ['fulltext'], 0, 0, [], 0),
659
'a-2':('a-2', ['fulltext'], 0, 0, ['a-1'], 1),
660
'a-3':('a-3', ['fulltext'], 0, 0, ['a-2'], 2),
663
def test_add_versions_fails_clean(self):
664
"""If add_versions fails in the middle, it restores a pristine state.
666
Any modifications that are made to the index are reset if all versions
669
# This cheats a little bit by passing in a generator which will
670
# raise an exception before the processing finishes
671
# Other possibilities would be to have an version with the wrong number
672
# of entries, or to make the backing transport unable to write any
675
knit = self.make_test_knit()
677
idx.add_version('a-1', ['fulltext'], 0, 0, [])
679
class StopEarly(Exception):
682
def generate_failure():
683
"""Add some entries and then raise an exception"""
684
yield ('a-2', ['fulltext'], 0, 0, ['a-1'])
685
yield ('a-3', ['fulltext'], 0, 0, ['a-2'])
688
# Assert the pre-condition
689
self.assertEqual(['a-1'], idx._history)
690
self.assertEqual({'a-1':('a-1', ['fulltext'], 0, 0, [], 0)}, idx._cache)
692
self.assertRaises(StopEarly, idx.add_versions, generate_failure())
694
# And it shouldn't be modified
695
self.assertEqual(['a-1'], idx._history)
696
self.assertEqual({'a-1':('a-1', ['fulltext'], 0, 0, [], 0)}, idx._cache)