/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_weave.py

  • Committer: Robert Collins
  • Date: 2006-03-01 02:01:47 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060301020147-62bb5465f75fbf40
Start check tests for knits (pending), and remove dead code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
868
868
        eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
869
869
        eq(wa.get_text('x1'), 'line from x1\n')
870
870
 
871
 
 
872
 
class Corruption(TestCase):
873
 
 
874
 
    def test_detection(self):
875
 
        # Test weaves detect corruption.
876
 
        #
877
 
        # Weaves contain a checksum of their texts.
878
 
        # When a text is extracted, this checksum should be
879
 
        # verified.
880
 
 
881
 
        w = Weave()
882
 
        w.add('v1', [], ['hello\n'])
883
 
        w.add('v2', ['v1'], ['hello\n', 'there\n'])
884
 
 
885
 
        # We are going to invasively corrupt the text
886
 
        # Make sure the internals of weave are the same
887
 
        self.assertEqual([('{', 0)
888
 
                        , 'hello\n'
889
 
                        , ('}', None)
890
 
                        , ('{', 1)
891
 
                        , 'there\n'
892
 
                        , ('}', None)
893
 
                        ], w._weave)
894
 
 
895
 
        self.assertEqual(['f572d396fae9206628714fb2ce00f72e94f2258f'
896
 
                        , '90f265c6e75f1c8f9ab76dcf85528352c5f215ef'
897
 
                        ], w._sha1s)
898
 
        w.check()
899
 
 
900
 
        # Corrupted
901
 
        w._weave[4] = 'There\n'
902
 
 
903
 
        self.assertEqual('hello\n', w.get_text('v1'))
904
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
905
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
906
 
        self.assertRaises(errors.WeaveInvalidChecksum, list, w.get_iter('v2'))
907
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
908
 
 
909
 
        # Corrected
910
 
        w._weave[4] = 'there\n'
911
 
        self.assertEqual('hello\nthere\n', w.get_text('v2'))
912
 
 
913
 
        #Invalid checksum, first digit changed
914
 
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
915
 
 
916
 
        self.assertEqual('hello\n', w.get_text('v1'))
917
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
918
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
919
 
        self.assertRaises(errors.WeaveInvalidChecksum, list, w.get_iter('v2'))
920
 
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
921
 
 
922
871
    def test_written_detection(self):
923
872
        # Test detection of weave file corruption.
924
873
        #