Lib/test/test_zlib.py - Issue 4454: zlib and zipimport should use bytes not bytearray Code Review (original) (raw)
OLD
NEW
1 import unittest
1 import unittest
2 from test import support
2 from test import support
3 import zlib
3 import zlib
4 import binascii
4 import binascii
5 import random
5 import random
6
6
7
7
8 class ChecksumTestCase(unittest.TestCase):
8 class ChecksumTestCase(unittest.TestCase):
9 # checksum test cases
9 # checksum test cases
10 def test_crc32start(self):
10 def test_crc32start(self):
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
145 # compress object in steps, decompress object in steps
145 # compress object in steps, decompress object in steps
146 source = source or HAMLET_SCENE
146 source = source or HAMLET_SCENE
147 data = source * 128
147 data = source * 128
148 co = zlib.compressobj()
148 co = zlib.compressobj()
149 bufs = []
149 bufs = []
150 for i in range(0, len(data), cx):
150 for i in range(0, len(data), cx):
151 bufs.append(co.compress(data[i:i+cx]))
151 bufs.append(co.compress(data[i:i+cx]))
152 bufs.append(co.flush())
152 bufs.append(co.flush())
153 combuf = b''.join(bufs)
153 combuf = b''.join(bufs)
154
154
155 self.assertEqual(data, zlib.decompress(combuf))
155 decombuf = zlib.decompress(combuf)
156 # Test type of return value
157 self.assertEqual(type(decombuf), bytes)
158 ········
159 self.assertEqual(data, decombuf)
156
160
157 dco = zlib.decompressobj()
161 dco = zlib.decompressobj()
158 bufs = []
162 bufs = []
159 for i in range(0, len(combuf), dcx):
163 for i in range(0, len(combuf), dcx):
160 bufs.append(dco.decompress(combuf[i:i+dcx]))
164 bufs.append(dco.decompress(combuf[i:i+dcx]))
161 self.assertEqual(b'', dco.unconsumed_tail, ########
165 self.assertEqual(b'', dco.unconsumed_tail, ########
162 "(A) uct should be b'': not %d long" %
166 "(A) uct should be b'': not %d long" %
163 len(dco.unconsumed_tail))
167 len(dco.unconsumed_tail))
164 self.assertEqual(b'', dco.unused_data)
168 self.assertEqual(b'', dco.unused_data)
165 if flush:
169 if flush:
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
341 c = zlib.compressobj()
345 c = zlib.compressobj()
342 c.compress(HAMLET_SCENE)
346 c.compress(HAMLET_SCENE)
343 c.flush()
347 c.flush()
344 self.assertRaises(ValueError, c.copy)
348 self.assertRaises(ValueError, c.copy)
345
349
346 if hasattr(zlib.decompressobj(), "copy"):
350 if hasattr(zlib.decompressobj(), "copy"):
347 def test_decompresscopy(self):
351 def test_decompresscopy(self):
348 # Test copying a decompression object
352 # Test copying a decompression object
349 data = HAMLET_SCENE
353 data = HAMLET_SCENE
350 comp = zlib.compress(data)
354 comp = zlib.compress(data)
351
355 # Test type of return value
356 self.assertEqual(type(comp), bytes)
357 ············
352 d0 = zlib.decompressobj()
358 d0 = zlib.decompressobj()
353 bufs0 = []
359 bufs0 = []
354 bufs0.append(d0.decompress(comp[:32]))
360 bufs0.append(d0.decompress(comp[:32]))
355
361
356 d1 = d0.copy()
362 d1 = d0.copy()
357 bufs1 = bufs0[:]
363 bufs1 = bufs0[:]
358
364
359 bufs0.append(d0.decompress(comp[32:]))
365 bufs0.append(d0.decompress(comp[32:]))
360 s0 = b''.join(bufs0)
366 s0 = b''.join(bufs0)
361
367
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
465 support.run_unittest(
471 support.run_unittest(
466 ChecksumTestCase,
472 ChecksumTestCase,
467 ExceptionTestCase,
473 ExceptionTestCase,
468 CompressTestCase,
474 CompressTestCase,
469 CompressObjectTestCase
475 CompressObjectTestCase
470 )
476 )
471
477
472 if __name__ == "__main__":
478 if __name__ == "__main__":
473 unittest.main() # XXX
479 unittest.main() # XXX
474 ###test_main()
480 ###test_main()
OLD
NEW