Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(34230)

Side by Side Diff: Lib/test/test_zlib.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_xmlrpc.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 import binascii 3 import binascii
4 import random 4 import random
5 import sys 5 import sys
6 from test.support import bigmemtest, _1G, _4G 6 from test.support import bigmemtest, _1G, _4G
7 7
8 zlib = support.import_module('zlib') 8 zlib = support.import_module('zlib')
9 9
10 requires_Compress_copy = unittest.skipUnless( 10 requires_Compress_copy = unittest.skipUnless(
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 combuf = b''.join(bufs) 304 combuf = b''.join(bufs)
305 self.assertEqual(data, zlib.decompress(combuf), 305 self.assertEqual(data, zlib.decompress(combuf),
306 'compressed data failure') 306 'compressed data failure')
307 307
308 dco = zlib.decompressobj() 308 dco = zlib.decompressobj()
309 bufs = [] 309 bufs = []
310 cb = combuf 310 cb = combuf
311 while cb: 311 while cb:
312 #max_length = 1 + len(cb)//10 312 #max_length = 1 + len(cb)//10
313 chunk = dco.decompress(cb, dcx) 313 chunk = dco.decompress(cb, dcx)
314 self.assertFalse(len(chunk) > dcx, 314 self.assertLessEqual(len(chunk), dcx)
315 'chunk too big (%d>%d)' % (len(chunk), dcx))
316 bufs.append(chunk) 315 bufs.append(chunk)
317 cb = dco.unconsumed_tail 316 cb = dco.unconsumed_tail
318 bufs.append(dco.flush()) 317 bufs.append(dco.flush())
319 self.assertEqual(data, b''.join(bufs), 'Wrong data retrieved') 318 self.assertEqual(data, b''.join(bufs), 'Wrong data retrieved')
320 319
321 def test_decompressmaxlen(self, flush=False): 320 def test_decompressmaxlen(self, flush=False):
322 # Check a decompression object with max_length specified 321 # Check a decompression object with max_length specified
323 data = HAMLET_SCENE * 128 322 data = HAMLET_SCENE * 128
324 co = zlib.compressobj() 323 co = zlib.compressobj()
325 bufs = [] 324 bufs = []
326 for i in range(0, len(data), 256): 325 for i in range(0, len(data), 256):
327 bufs.append(co.compress(data[i:i+256])) 326 bufs.append(co.compress(data[i:i+256]))
328 bufs.append(co.flush()) 327 bufs.append(co.flush())
329 combuf = b''.join(bufs) 328 combuf = b''.join(bufs)
330 self.assertEqual(data, zlib.decompress(combuf), 329 self.assertEqual(data, zlib.decompress(combuf),
331 'compressed data failure') 330 'compressed data failure')
332 331
333 dco = zlib.decompressobj() 332 dco = zlib.decompressobj()
334 bufs = [] 333 bufs = []
335 cb = combuf 334 cb = combuf
336 while cb: 335 while cb:
337 max_length = 1 + len(cb)//10 336 max_length = 1 + len(cb)//10
338 chunk = dco.decompress(cb, max_length) 337 chunk = dco.decompress(cb, max_length)
339 self.assertFalse(len(chunk) > max_length, 338 self.assertLessEqual(len(chunk), max_length)
340 'chunk too big (%d>%d)' % (len(chunk),max_length))
341 bufs.append(chunk) 339 bufs.append(chunk)
342 cb = dco.unconsumed_tail 340 cb = dco.unconsumed_tail
343 if flush: 341 if flush:
344 bufs.append(dco.flush()) 342 bufs.append(dco.flush())
345 else: 343 else:
346 while chunk: 344 while chunk:
347 chunk = dco.decompress(b'', max_length) 345 chunk = dco.decompress(b'', max_length)
348 self.assertFalse(len(chunk) > max_length, 346 self.assertLessEqual(len(chunk), max_length)
349 'chunk too big (%d>%d)' % (len(chunk),max_length))
350 bufs.append(chunk) 347 bufs.append(chunk)
351 self.assertEqual(data, b''.join(bufs), 'Wrong data retrieved') 348 self.assertEqual(data, b''.join(bufs), 'Wrong data retrieved')
352 349
353 def test_decompressmaxlenflush(self): 350 def test_decompressmaxlenflush(self):
354 self.test_decompressmaxlen(flush=True) 351 self.test_decompressmaxlen(flush=True)
355 352
356 def test_maxlenmisc(self): 353 def test_maxlenmisc(self):
357 # Misc tests of max_length 354 # Misc tests of max_length
358 dco = zlib.decompressobj() 355 dco = zlib.decompressobj()
359 self.assertRaises(ValueError, dco.decompress, b"", -1) 356 self.assertRaises(ValueError, dco.decompress, b"", -1)
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ChecksumTestCase, 713 ChecksumTestCase,
717 ChecksumBigBufferTestCase, 714 ChecksumBigBufferTestCase,
718 ExceptionTestCase, 715 ExceptionTestCase,
719 CompressTestCase, 716 CompressTestCase,
720 CompressObjectTestCase 717 CompressObjectTestCase
721 ) 718 )
722 719
723 if __name__ == "__main__": 720 if __name__ == "__main__":
724 unittest.main() # XXX 721 unittest.main() # XXX
725 ###test_main() 722 ###test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_xmlrpc.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+