This commit was manufactured by cvs2svn to create tag 'r211c1'.
[python/dscho.git] / Lib / test / test_gzip.py
blob8ff8c337e73e05c05c5e69a5cdcf1d52d5c3fa3d
1 from test_support import verify
2 import sys, os
3 import gzip, tempfile
5 filename = tempfile.mktemp()
7 data1 = """ int length=DEFAULTALLOC, err = Z_OK;
8 PyObject *RetVal;
9 int flushmode = Z_FINISH;
10 unsigned long start_total_out;
12 """
14 data2 = """/* zlibmodule.c -- gzip-compatible data compression */
15 /* See http://www.cdrom.com/pub/infozip/zlib/ */
16 /* See http://www.winimage.com/zLibDll for Windows */
17 """
19 f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
21 f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
22 verify(d == data1*50)
24 # Append to the previous file
25 f = gzip.GzipFile(filename, 'ab') ; f.write(data2 * 15) ; f.close()
27 f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
28 verify(d == (data1*50) + (data2*15))
30 # Try .readline() with varying line lengths
32 f = gzip.GzipFile(filename, 'rb')
33 line_length = 0
34 while 1:
35 L = f.readline(line_length)
36 if L == "" and line_length != 0: break
37 verify(len(L) <= line_length)
38 line_length = (line_length + 1) % 50
39 f.close()
41 # Try .readlines()
43 f = gzip.GzipFile(filename, 'rb')
44 L = f.readlines()
45 f.close()
47 f = gzip.GzipFile(filename, 'rb')
48 while 1:
49 L = f.readlines(150)
50 if L == []: break
51 f.close()
54 os.unlink(filename)