contrib/python-zstandard/tests/test_compressor.py
changeset 42937 69de49c4e39c
parent 42070 675775c33ab6
child 43994 de7838053207
equal deleted inserted replaced
42936:2da754532dd3 42937:69de49c4e39c
  1036             samples.append(b'foobar' * 64)
  1036             samples.append(b'foobar' * 64)
  1037 
  1037 
  1038         d = zstd.train_dictionary(8192, samples)
  1038         d = zstd.train_dictionary(8192, samples)
  1039 
  1039 
  1040         h = hashlib.sha1(d.as_bytes()).hexdigest()
  1040         h = hashlib.sha1(d.as_bytes()).hexdigest()
  1041         self.assertEqual(h, '88ca0d38332aff379d4ced166a51c280a7679aad')
  1041         self.assertEqual(h, '7a2e59a876db958f74257141045af8f912e00d4e')
  1042 
  1042 
  1043         buffer = NonClosingBytesIO()
  1043         buffer = NonClosingBytesIO()
  1044         cctx = zstd.ZstdCompressor(level=9, dict_data=d)
  1044         cctx = zstd.ZstdCompressor(level=9, dict_data=d)
  1045         with cctx.stream_writer(buffer) as compressor:
  1045         with cctx.stream_writer(buffer) as compressor:
  1046             self.assertEqual(compressor.write(b'foo'), 0)
  1046             self.assertEqual(compressor.write(b'foo'), 0)
  1054         self.assertEqual(params.window_size, 2097152)
  1054         self.assertEqual(params.window_size, 2097152)
  1055         self.assertEqual(params.dict_id, d.dict_id())
  1055         self.assertEqual(params.dict_id, d.dict_id())
  1056         self.assertFalse(params.has_checksum)
  1056         self.assertFalse(params.has_checksum)
  1057 
  1057 
  1058         h = hashlib.sha1(compressed).hexdigest()
  1058         h = hashlib.sha1(compressed).hexdigest()
  1059         self.assertEqual(h, '8703b4316f274d26697ea5dd480f29c08e85d940')
  1059         self.assertEqual(h, '0a7c05635061f58039727cdbe76388c6f4cfef06')
  1060 
  1060 
  1061         source = b'foo' + b'bar' + (b'foo' * 16384)
  1061         source = b'foo' + b'bar' + (b'foo' * 16384)
  1062 
  1062 
  1063         dctx = zstd.ZstdDecompressor(dict_data=d)
  1063         dctx = zstd.ZstdDecompressor(dict_data=d)
  1064 
  1064 
  1089         self.assertEqual(params.window_size, 1048576)
  1089         self.assertEqual(params.window_size, 1048576)
  1090         self.assertEqual(params.dict_id, 0)
  1090         self.assertEqual(params.dict_id, 0)
  1091         self.assertFalse(params.has_checksum)
  1091         self.assertFalse(params.has_checksum)
  1092 
  1092 
  1093         h = hashlib.sha1(compressed).hexdigest()
  1093         h = hashlib.sha1(compressed).hexdigest()
  1094         self.assertEqual(h, '2a8111d72eb5004cdcecbdac37da9f26720d30ef')
  1094         self.assertEqual(h, 'dd4bb7d37c1a0235b38a2f6b462814376843ef0b')
  1095 
  1095 
  1096     def test_write_checksum(self):
  1096     def test_write_checksum(self):
  1097         no_checksum = NonClosingBytesIO()
  1097         no_checksum = NonClosingBytesIO()
  1098         cctx = zstd.ZstdCompressor(level=1)
  1098         cctx = zstd.ZstdCompressor(level=1)
  1099         with cctx.stream_writer(no_checksum) as compressor:
  1099         with cctx.stream_writer(no_checksum) as compressor: