--- test_gzip.py.orig 2007-03-09 09:54:41.000000000 +0100 +++ test_gzip.py 2007-03-09 10:16:54.000000000 +0100 @@ -20,6 +20,16 @@ /* See http://www.winimage.com/zLibDll for Windows */ """ +class InputStream: + """Restrict a File to reading only""" + + def __init__(self, f, testcase): + self.testcase = testcase + self.read = f.read + self.close = f.close + + def __getattr__(self, name): + self.testcase.fail("Trying to use '%s' attribute of the file object" % name) class TestGzip(unittest.TestCase): filename = test_support.TESTFN @@ -54,8 +64,9 @@ self.test_write() # Append to the previous file f = gzip.GzipFile(self.filename, 'ab') ; f.write(data2 * 15) ; f.close() - - f = gzip.GzipFile(self.filename, 'rb') ; d = f.read() ; f.close() + # wrap file into InputStream to make shure that read() doesn't seek() + f_ = InputStream(open(self.filename, 'rb'), self) + f = gzip.GzipFile(fileobj=f_) ; d = f.read() ; f.close() self.assertEqual(d, (data1*50) + (data2*15)) def test_many_append(self): @@ -85,7 +96,10 @@ self.test_write() # Try .readline() with varying line lengths - f = gzip.GzipFile(self.filename, 'rb') + # wrap file into InputStream to make shure that + # readline() doesn't seek() + f_ = InputStream(open(self.filename, 'rb'), self) + f = gzip.GzipFile(fileobj = f_) line_length = 0 while 1: L = f.readline(line_length)