~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    network_bytes_to_kind_and_offset,
63
63
    RecordingVersionedFilesDecorator,
64
64
    )
65
 
 
66
 
 
67
 
compiled_knit_feature = tests.ModuleAvailableFeature(
68
 
                            'bzrlib._knit_load_data_pyx')
 
65
from bzrlib.tests import (
 
66
    features,
 
67
    )
 
68
 
 
69
 
 
70
compiled_knit_feature = features.ModuleAvailableFeature(
 
71
    'bzrlib._knit_load_data_pyx')
69
72
 
70
73
 
71
74
class KnitContentTestsMixin(object):
444
447
        except _TestException, e:
445
448
            retry_exc = errors.RetryWithNewPacks(None, reload_occurred=False,
446
449
                                                 exc_info=sys.exc_info())
 
450
        # GZ 2010-08-10: Cycle with exc_info affects 3 tests
447
451
        return retry_exc
448
452
 
449
453
    def test_read_from_several_packs(self):
732
736
 
733
737
    def make_multiple_records(self):
734
738
        """Create the content for multiple records."""
735
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
739
        sha1sum = osutils.sha_string('foo\nbar\n')
736
740
        total_txt = []
737
741
        gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
738
742
                                        'foo\n'
741
745
                                        % (sha1sum,))
742
746
        record_1 = (0, len(gz_txt), sha1sum)
743
747
        total_txt.append(gz_txt)
744
 
        sha1sum = osutils.sha('baz\n').hexdigest()
 
748
        sha1sum = osutils.sha_string('baz\n')
745
749
        gz_txt = self.create_gz_content('version rev-id-2 1 %s\n'
746
750
                                        'baz\n'
747
751
                                        'end rev-id-2\n'
751
755
        return total_txt, record_1, record_2
752
756
 
753
757
    def test_valid_knit_data(self):
754
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
758
        sha1sum = osutils.sha_string('foo\nbar\n')
755
759
        gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
756
760
                                        'foo\n'
757
761
                                        'bar\n'
788
792
                         raw_contents)
789
793
 
790
794
    def test_not_enough_lines(self):
791
 
        sha1sum = osutils.sha('foo\n').hexdigest()
 
795
        sha1sum = osutils.sha_string('foo\n')
792
796
        # record says 2 lines data says 1
793
797
        gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
794
798
                                        'foo\n'
806
810
        self.assertEqual([(('rev-id-1',),  gz_txt, sha1sum)], raw_contents)
807
811
 
808
812
    def test_too_many_lines(self):
809
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
813
        sha1sum = osutils.sha_string('foo\nbar\n')
810
814
        # record says 1 lines data says 2
811
815
        gz_txt = self.create_gz_content('version rev-id-1 1 %s\n'
812
816
                                        'foo\n'
825
829
        self.assertEqual([(('rev-id-1',), gz_txt, sha1sum)], raw_contents)
826
830
 
827
831
    def test_mismatched_version_id(self):
828
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
832
        sha1sum = osutils.sha_string('foo\nbar\n')
829
833
        gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
830
834
                                        'foo\n'
831
835
                                        'bar\n'
844
848
            knit._read_records_iter_raw(records))
845
849
 
846
850
    def test_uncompressed_data(self):
847
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
851
        sha1sum = osutils.sha_string('foo\nbar\n')
848
852
        txt = ('version rev-id-1 2 %s\n'
849
853
               'foo\n'
850
854
               'bar\n'
864
868
            knit._read_records_iter_raw(records))
865
869
 
866
870
    def test_corrupted_data(self):
867
 
        sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
871
        sha1sum = osutils.sha_string('foo\nbar\n')
868
872
        gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
869
873
                                        'foo\n'
870
874
                                        'bar\n'
1192
1196
            self.assertRaises(errors.KnitCorrupt, index.keys)
1193
1197
        except TypeError, e:
1194
1198
            if (str(e) == ('exceptions must be strings, classes, or instances,'
1195
 
                           ' not exceptions.IndexError')
1196
 
                and sys.version_info[0:2] >= (2,5)):
 
1199
                           ' not exceptions.IndexError')):
1197
1200
                self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
1198
1201
                                  ' raising new style exceptions with python'
1199
1202
                                  ' >=2.5')
1212
1215
            self.assertRaises(errors.KnitCorrupt, index.keys)
1213
1216
        except TypeError, e:
1214
1217
            if (str(e) == ('exceptions must be strings, classes, or instances,'
1215
 
                           ' not exceptions.ValueError')
1216
 
                and sys.version_info[0:2] >= (2,5)):
 
1218
                           ' not exceptions.ValueError')):
1217
1219
                self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
1218
1220
                                  ' raising new style exceptions with python'
1219
1221
                                  ' >=2.5')
1232
1234
            self.assertRaises(errors.KnitCorrupt, index.keys)
1233
1235
        except TypeError, e:
1234
1236
            if (str(e) == ('exceptions must be strings, classes, or instances,'
1235
 
                           ' not exceptions.ValueError')
1236
 
                and sys.version_info[0:2] >= (2,5)):
 
1237
                           ' not exceptions.ValueError')):
1237
1238
                self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
1238
1239
                                  ' raising new style exceptions with python'
1239
1240
                                  ' >=2.5')
1250
1251
            self.assertRaises(errors.KnitCorrupt, index.keys)
1251
1252
        except TypeError, e:
1252
1253
            if (str(e) == ('exceptions must be strings, classes, or instances,'
1253
 
                           ' not exceptions.ValueError')
1254
 
                and sys.version_info[0:2] >= (2,5)):
 
1254
                           ' not exceptions.ValueError')):
1255
1255
                self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
1256
1256
                                  ' raising new style exceptions with python'
1257
1257
                                  ' >=2.5')
1268
1268
            self.assertRaises(errors.KnitCorrupt, index.keys)
1269
1269
        except TypeError, e:
1270
1270
            if (str(e) == ('exceptions must be strings, classes, or instances,'
1271
 
                           ' not exceptions.ValueError')
1272
 
                and sys.version_info[0:2] >= (2,5)):
 
1271
                           ' not exceptions.ValueError')):
1273
1272
                self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
1274
1273
                                  ' raising new style exceptions with python'
1275
1274
                                  ' >=2.5')
1604
1603
        # could leave an empty .kndx file, which bzr would later claim was a
1605
1604
        # corrupted file since the header was not present. In reality, the file
1606
1605
        # just wasn't created, so it should be ignored.
1607
 
        t = transport.get_transport('.')
 
1606
        t = transport.get_transport_from_path('.')
1608
1607
        t.put_bytes('test.kndx', '')
1609
1608
 
1610
1609
        knit = self.make_test_knit()
1611
1610
 
1612
1611
    def test_knit_index_checks_header(self):
1613
 
        t = transport.get_transport('.')
 
1612
        t = transport.get_transport_from_path('.')
1614
1613
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1615
1614
        k = self.make_test_knit()
1616
1615
        self.assertRaises(KnitHeaderError, k.keys)
2444
2443
        key_basis = ('bar',)
2445
2444
        key_missing = ('missing',)
2446
2445
        test.add_lines(key, (), ['foo\n'])
2447
 
        key_sha1sum = osutils.sha('foo\n').hexdigest()
 
2446
        key_sha1sum = osutils.sha_string('foo\n')
2448
2447
        sha1s = test.get_sha1s([key])
2449
2448
        self.assertEqual({key: key_sha1sum}, sha1s)
2450
2449
        self.assertEqual([], basis.calls)
2452
2451
        # directly (rather than via text reconstruction) so that remote servers
2453
2452
        # etc don't have to answer with full content.
2454
2453
        basis.add_lines(key_basis, (), ['foo\n', 'bar\n'])
2455
 
        basis_sha1sum = osutils.sha('foo\nbar\n').hexdigest()
 
2454
        basis_sha1sum = osutils.sha_string('foo\nbar\n')
2456
2455
        basis.calls = []
2457
2456
        sha1s = test.get_sha1s([key, key_missing, key_basis])
2458
2457
        self.assertEqual({key: key_sha1sum,