summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zlib.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2001-08-10 15:50:11 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2001-08-10 15:50:11 (GMT)
commitfcfc8d5c0e58644d60e73a19679243a86d0bdc84 (patch)
tree08ea3636915d78c5ac22f741842c2c00214fa6b8 /Lib/test/test_zlib.py
parent315cd29ecf694b23715165cda8628e2444371c98 (diff)
downloadcpython-fcfc8d5c0e58644d60e73a19679243a86d0bdc84.zip
cpython-fcfc8d5c0e58644d60e73a19679243a86d0bdc84.tar.gz
cpython-fcfc8d5c0e58644d60e73a19679243a86d0bdc84.tar.bz2
Patch #441091 from Finn Bock: the more advanced flush options are not
available in java, so only use the advanced flush options if they are defined in the zlib module.
Diffstat (limited to 'Lib/test/test_zlib.py')
-rw-r--r--Lib/test/test_zlib.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 198f0d9..439db22 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -78,7 +78,10 @@ else:
# Test flush() with the various options, using all the different levels
# in order to provide more variations.
-for sync in [zlib.Z_NO_FLUSH, zlib.Z_SYNC_FLUSH, zlib.Z_FULL_FLUSH]:
+sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH']
+sync_opt = [getattr(zlib, opt) for opt in sync_opt if hasattr(zlib, opt)]
+
+for sync in sync_opt:
for level in range(10):
obj = zlib.compressobj( level )
d = obj.compress( buf[:3000] )
@@ -96,23 +99,25 @@ random.seed(1)
print 'Testing on 17K of random data'
-# Create compressor and decompressor objects
-c=zlib.compressobj(9)
-d=zlib.decompressobj()
+if hasattr(zlib, 'Z_SYNC_FLUSH'):
+
+ # Create compressor and decompressor objects
+ c=zlib.compressobj(9)
+ d=zlib.decompressobj()
-# Try 17K of data
-# generate random data stream
-a=""
-for i in range(17*1024):
- a=a+chr(random.randint(0,255))
+ # Try 17K of data
+ # generate random data stream
+ a=""
+ for i in range(17*1024):
+ a=a+chr(random.randint(0,255))
-# compress, sync-flush, and decompress
-t = d.decompress( c.compress(a)+c.flush(zlib.Z_SYNC_FLUSH) )
+ # compress, sync-flush, and decompress
+ t = d.decompress( c.compress(a)+c.flush(zlib.Z_SYNC_FLUSH) )
-# if decompressed data is different from the input data, choke.
-if len(t) != len(a):
- print len(a),len(t),len(d.unused_data)
- raise TestFailed, "output of 17K doesn't match"
+ # if decompressed data is different from the input data, choke.
+ if len(t) != len(a):
+ print len(a),len(t),len(d.unused_data)
+ raise TestFailed, "output of 17K doesn't match"
def ignore():
"""An empty function with a big string.