Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 1 | """Test script for the gzip module. |
| 2 | """ |
| 3 | |
| 4 | import unittest |
| 5 | from test import test_support |
Christian Heimes | c5f05e4 | 2008-02-23 17:40:11 +0000 | [diff] [blame] | 6 | import os |
Antoine Pitrou | 673ddf9 | 2010-01-03 22:29:56 +0000 | [diff] [blame] | 7 | import io |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 8 | import struct |
Ezio Melotti | 1036a7f | 2009-09-12 14:43:43 +0000 | [diff] [blame] | 9 | gzip = test_support.import_module('gzip') |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 10 | |
| 11 | data1 = """ int length=DEFAULTALLOC, err = Z_OK; |
| 12 | PyObject *RetVal; |
| 13 | int flushmode = Z_FINISH; |
| 14 | unsigned long start_total_out; |
| 15 | |
| 16 | """ |
| 17 | |
| 18 | data2 = """/* zlibmodule.c -- gzip-compatible data compression */ |
Neal Norwitz | 014f103 | 2004-07-29 03:55:56 +0000 | [diff] [blame] | 19 | /* See http://www.gzip.org/zlib/ |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 20 | /* See http://www.winimage.com/zLibDll for Windows */ |
| 21 | """ |
| 22 | |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 23 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 24 | class TestGzip(unittest.TestCase): |
| 25 | filename = test_support.TESTFN |
Tim Peters | 5cfb05e | 2004-07-27 21:02:02 +0000 | [diff] [blame] | 26 | |
Georg Brandl | e08e3d0 | 2008-05-25 08:07:37 +0000 | [diff] [blame] | 27 | def setUp(self): |
Neal Norwitz | 36a59b4 | 2008-04-10 05:46:39 +0000 | [diff] [blame] | 28 | test_support.unlink(self.filename) |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 29 | |
Georg Brandl | e08e3d0 | 2008-05-25 08:07:37 +0000 | [diff] [blame] | 30 | def tearDown(self): |
Neal Norwitz | 36a59b4 | 2008-04-10 05:46:39 +0000 | [diff] [blame] | 31 | test_support.unlink(self.filename) |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 32 | |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 33 | |
Georg Brandl | e08e3d0 | 2008-05-25 08:07:37 +0000 | [diff] [blame] | 34 | def test_write(self): |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 35 | with gzip.GzipFile(self.filename, 'wb') as f: |
| 36 | f.write(data1 * 50) |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 37 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 38 | # Try flush and fileno. |
| 39 | f.flush() |
| 40 | f.fileno() |
| 41 | if hasattr(os, 'fsync'): |
| 42 | os.fsync(f.fileno()) |
| 43 | f.close() |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 44 | |
Georg Brandl | e08e3d0 | 2008-05-25 08:07:37 +0000 | [diff] [blame] | 45 | # Test multiple close() calls. |
| 46 | f.close() |
| 47 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 48 | def test_read(self): |
| 49 | self.test_write() |
| 50 | # Try reading. |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 51 | with gzip.GzipFile(self.filename, 'r') as f: |
| 52 | d = f.read() |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 53 | self.assertEqual(d, data1*50) |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 54 | |
Nadeem Vawda | dd72b3f | 2012-10-21 18:15:05 +0200 | [diff] [blame] | 55 | def test_read_universal_newlines(self): |
| 56 | # Issue #5148: Reading breaks when mode contains 'U'. |
| 57 | self.test_write() |
| 58 | with gzip.GzipFile(self.filename, 'rU') as f: |
| 59 | d = f.read() |
| 60 | self.assertEqual(d, data1*50) |
| 61 | |
Antoine Pitrou | 76a66aa | 2010-10-06 21:26:52 +0000 | [diff] [blame] | 62 | def test_io_on_closed_object(self): |
| 63 | # Test that I/O operations on closed GzipFile objects raise a |
| 64 | # ValueError, just like the corresponding functions on file objects. |
| 65 | |
| 66 | # Write to a file, open it for reading, then close it. |
| 67 | self.test_write() |
| 68 | f = gzip.GzipFile(self.filename, 'r') |
| 69 | f.close() |
| 70 | with self.assertRaises(ValueError): |
| 71 | f.read(1) |
| 72 | with self.assertRaises(ValueError): |
| 73 | f.seek(0) |
| 74 | with self.assertRaises(ValueError): |
| 75 | f.tell() |
| 76 | # Open the file for writing, then close it. |
| 77 | f = gzip.GzipFile(self.filename, 'w') |
| 78 | f.close() |
| 79 | with self.assertRaises(ValueError): |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 80 | f.write('') |
Antoine Pitrou | 76a66aa | 2010-10-06 21:26:52 +0000 | [diff] [blame] | 81 | with self.assertRaises(ValueError): |
| 82 | f.flush() |
| 83 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 84 | def test_append(self): |
| 85 | self.test_write() |
| 86 | # Append to the previous file |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 87 | with gzip.GzipFile(self.filename, 'ab') as f: |
| 88 | f.write(data2 * 15) |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 89 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 90 | with gzip.GzipFile(self.filename, 'rb') as f: |
| 91 | d = f.read() |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 92 | self.assertEqual(d, (data1*50) + (data2*15)) |
Andrew M. Kuchling | 85ab738 | 2000-07-29 20:18:34 +0000 | [diff] [blame] | 93 | |
Andrew M. Kuchling | 01cb47b | 2005-06-09 14:19:32 +0000 | [diff] [blame] | 94 | def test_many_append(self): |
| 95 | # Bug #1074261 was triggered when reading a file that contained |
| 96 | # many, many members. Create such a file and verify that reading it |
| 97 | # works. |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 98 | with gzip.open(self.filename, 'wb', 9) as f: |
Andrew M. Kuchling | 01cb47b | 2005-06-09 14:19:32 +0000 | [diff] [blame] | 99 | f.write('a') |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 100 | for i in range(0, 200): |
| 101 | with gzip.open(self.filename, "ab", 9) as f: # append |
| 102 | f.write('a') |
Andrew M. Kuchling | 01cb47b | 2005-06-09 14:19:32 +0000 | [diff] [blame] | 103 | |
| 104 | # Try reading the file |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 105 | with gzip.open(self.filename, "rb") as zgfile: |
| 106 | contents = "" |
| 107 | while 1: |
| 108 | ztxt = zgfile.read(8192) |
| 109 | contents += ztxt |
| 110 | if not ztxt: break |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 111 | self.assertEqual(contents, 'a'*201) |
Andrew M. Kuchling | 01cb47b | 2005-06-09 14:19:32 +0000 | [diff] [blame] | 112 | |
Antoine Pitrou | 673ddf9 | 2010-01-03 22:29:56 +0000 | [diff] [blame] | 113 | def test_buffered_reader(self): |
| 114 | # Issue #7471: a GzipFile can be wrapped in a BufferedReader for |
| 115 | # performance. |
| 116 | self.test_write() |
| 117 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 118 | with gzip.GzipFile(self.filename, 'rb') as f: |
| 119 | with io.BufferedReader(f) as r: |
| 120 | lines = [line for line in r] |
Antoine Pitrou | 673ddf9 | 2010-01-03 22:29:56 +0000 | [diff] [blame] | 121 | |
| 122 | self.assertEqual(lines, 50 * data1.splitlines(True)) |
Andrew M. Kuchling | 01cb47b | 2005-06-09 14:19:32 +0000 | [diff] [blame] | 123 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 124 | def test_readline(self): |
| 125 | self.test_write() |
| 126 | # Try .readline() with varying line lengths |
Martin v. Löwis | 8cc965c | 2001-08-09 07:21:56 +0000 | [diff] [blame] | 127 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 128 | with gzip.GzipFile(self.filename, 'rb') as f: |
| 129 | line_length = 0 |
| 130 | while 1: |
| 131 | L = f.readline(line_length) |
| 132 | if not L and line_length != 0: break |
| 133 | self.assertTrue(len(L) <= line_length) |
| 134 | line_length = (line_length + 1) % 50 |
Martin v. Löwis | 8cc965c | 2001-08-09 07:21:56 +0000 | [diff] [blame] | 135 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 136 | def test_readlines(self): |
| 137 | self.test_write() |
| 138 | # Try .readlines() |
Andrew M. Kuchling | 605ebdd | 1999-03-25 21:50:27 +0000 | [diff] [blame] | 139 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 140 | with gzip.GzipFile(self.filename, 'rb') as f: |
| 141 | L = f.readlines() |
Skip Montanaro | 12424bc | 2002-05-23 01:43:05 +0000 | [diff] [blame] | 142 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 143 | with gzip.GzipFile(self.filename, 'rb') as f: |
| 144 | while 1: |
| 145 | L = f.readlines(150) |
| 146 | if L == []: break |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 147 | |
| 148 | def test_seek_read(self): |
| 149 | self.test_write() |
| 150 | # Try seek, read test |
| 151 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 152 | with gzip.GzipFile(self.filename) as f: |
| 153 | while 1: |
| 154 | oldpos = f.tell() |
| 155 | line1 = f.readline() |
| 156 | if not line1: break |
| 157 | newpos = f.tell() |
| 158 | f.seek(oldpos) # negative seek |
| 159 | if len(line1)>10: |
| 160 | amount = 10 |
| 161 | else: |
| 162 | amount = len(line1) |
| 163 | line2 = f.read(amount) |
| 164 | self.assertEqual(line1[:amount], line2) |
| 165 | f.seek(newpos) # positive seek |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 166 | |
Martin v. Löwis | 065f0c8 | 2006-11-12 10:41:39 +0000 | [diff] [blame] | 167 | def test_seek_whence(self): |
| 168 | self.test_write() |
| 169 | # Try seek(whence=1), read test |
| 170 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 171 | with gzip.GzipFile(self.filename) as f: |
| 172 | f.read(10) |
| 173 | f.seek(10, whence=1) |
| 174 | y = f.read(10) |
Ezio Melotti | 2623a37 | 2010-11-21 13:34:58 +0000 | [diff] [blame] | 175 | self.assertEqual(y, data1[20:30]) |
Tim Peters | f733abb | 2007-01-30 03:03:46 +0000 | [diff] [blame] | 176 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 177 | def test_seek_write(self): |
| 178 | # Try seek, write test |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 179 | with gzip.GzipFile(self.filename, 'w') as f: |
| 180 | for pos in range(0, 256, 16): |
| 181 | f.seek(pos) |
| 182 | f.write('GZ\n') |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 183 | |
| 184 | def test_mode(self): |
| 185 | self.test_write() |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 186 | with gzip.GzipFile(self.filename, 'r') as f: |
| 187 | self.assertEqual(f.myfileobj.mode, 'rb') |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 188 | |
Lars Gustäbel | 5b1a785 | 2007-02-13 16:09:24 +0000 | [diff] [blame] | 189 | def test_1647484(self): |
| 190 | for mode in ('wb', 'rb'): |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 191 | with gzip.GzipFile(self.filename, mode) as f: |
| 192 | self.assertTrue(hasattr(f, "name")) |
| 193 | self.assertEqual(f.name, self.filename) |
Lars Gustäbel | 5b1a785 | 2007-02-13 16:09:24 +0000 | [diff] [blame] | 194 | |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 195 | def test_mtime(self): |
| 196 | mtime = 123456789 |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 197 | with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: |
| 198 | fWrite.write(data1) |
| 199 | with gzip.GzipFile(self.filename) as fRead: |
| 200 | dataRead = fRead.read() |
| 201 | self.assertEqual(dataRead, data1) |
| 202 | self.assertTrue(hasattr(fRead, 'mtime')) |
| 203 | self.assertEqual(fRead.mtime, mtime) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 204 | |
| 205 | def test_metadata(self): |
| 206 | mtime = 123456789 |
| 207 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 208 | with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: |
| 209 | fWrite.write(data1) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 210 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 211 | with open(self.filename, 'rb') as fRead: |
| 212 | # see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 213 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 214 | idBytes = fRead.read(2) |
| 215 | self.assertEqual(idBytes, '\x1f\x8b') # gzip ID |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 216 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 217 | cmByte = fRead.read(1) |
| 218 | self.assertEqual(cmByte, '\x08') # deflate |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 219 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 220 | flagsByte = fRead.read(1) |
| 221 | self.assertEqual(flagsByte, '\x08') # only the FNAME flag is set |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 222 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 223 | mtimeBytes = fRead.read(4) |
| 224 | self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 225 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 226 | xflByte = fRead.read(1) |
| 227 | self.assertEqual(xflByte, '\x02') # maximum compression |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 228 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 229 | osByte = fRead.read(1) |
| 230 | self.assertEqual(osByte, '\xff') # OS "unknown" (OS-independent) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 231 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 232 | # Since the FNAME flag is set, the zero-terminated filename follows. |
| 233 | # RFC 1952 specifies that this is the name of the input file, if any. |
| 234 | # However, the gzip module defaults to storing the name of the output |
| 235 | # file in this field. |
| 236 | expected = self.filename.encode('Latin-1') + '\x00' |
| 237 | nameBytes = fRead.read(len(expected)) |
| 238 | self.assertEqual(nameBytes, expected) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 239 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 240 | # Since no other flags were set, the header ends here. |
| 241 | # Rather than process the compressed data, let's seek to the trailer. |
| 242 | fRead.seek(os.stat(self.filename).st_size - 8) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 243 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 244 | crc32Bytes = fRead.read(4) # CRC32 of uncompressed data [data1] |
| 245 | self.assertEqual(crc32Bytes, '\xaf\xd7d\x83') |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 246 | |
Brian Curtin | 31cf8d0 | 2010-10-13 23:51:19 +0000 | [diff] [blame] | 247 | isizeBytes = fRead.read(4) |
| 248 | self.assertEqual(isizeBytes, struct.pack('<i', len(data1))) |
Antoine Pitrou | f0d2c3f | 2009-01-04 21:29:23 +0000 | [diff] [blame] | 249 | |
Antoine Pitrou | b74fc2b | 2009-01-10 16:13:45 +0000 | [diff] [blame] | 250 | def test_with_open(self): |
| 251 | # GzipFile supports the context management protocol |
| 252 | with gzip.GzipFile(self.filename, "wb") as f: |
| 253 | f.write(b"xxx") |
| 254 | f = gzip.GzipFile(self.filename, "rb") |
| 255 | f.close() |
| 256 | try: |
| 257 | with f: |
| 258 | pass |
| 259 | except ValueError: |
| 260 | pass |
| 261 | else: |
| 262 | self.fail("__enter__ on a closed file didn't raise an exception") |
| 263 | try: |
| 264 | with gzip.GzipFile(self.filename, "wb") as f: |
Ezio Melotti | dde5b94 | 2010-02-03 05:37:26 +0000 | [diff] [blame] | 265 | 1 // 0 |
Antoine Pitrou | b74fc2b | 2009-01-10 16:13:45 +0000 | [diff] [blame] | 266 | except ZeroDivisionError: |
| 267 | pass |
| 268 | else: |
Ezio Melotti | dde5b94 | 2010-02-03 05:37:26 +0000 | [diff] [blame] | 269 | self.fail("1 // 0 didn't raise an exception") |
Antoine Pitrou | b74fc2b | 2009-01-10 16:13:45 +0000 | [diff] [blame] | 270 | |
Antoine Pitrou | 5a9112c | 2010-01-13 14:32:10 +0000 | [diff] [blame] | 271 | def test_zero_padded_file(self): |
| 272 | with gzip.GzipFile(self.filename, "wb") as f: |
| 273 | f.write(data1 * 50) |
| 274 | |
| 275 | # Pad the file with zeroes |
| 276 | with open(self.filename, "ab") as f: |
| 277 | f.write("\x00" * 50) |
| 278 | |
| 279 | with gzip.GzipFile(self.filename, "rb") as f: |
| 280 | d = f.read() |
| 281 | self.assertEqual(d, data1 * 50, "Incorrect data in file") |
| 282 | |
Nadeem Vawda | d7664de | 2012-01-19 00:40:46 +0200 | [diff] [blame] | 283 | def test_fileobj_from_fdopen(self): |
| 284 | # Issue #13781: Creating a GzipFile using a fileobj from os.fdopen() |
| 285 | # should not embed the fake filename "<fdopen>" in the output file. |
| 286 | fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT) |
| 287 | with os.fdopen(fd, "wb") as f: |
| 288 | with gzip.GzipFile(fileobj=f, mode="w") as g: |
| 289 | self.assertEqual(g.name, "") |
| 290 | |
Serhiy Storchaka | 371432b | 2013-04-08 22:33:55 +0300 | [diff] [blame] | 291 | def test_read_with_extra(self): |
| 292 | # Gzip data with an extra field |
| 293 | gzdata = (b'\x1f\x8b\x08\x04\xb2\x17cQ\x02\xff' |
| 294 | b'\x05\x00Extra' |
| 295 | b'\x0bI-.\x01\x002\xd1Mx\x04\x00\x00\x00') |
| 296 | with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f: |
| 297 | self.assertEqual(f.read(), b'Test') |
Serhiy Storchaka | 353e54e | 2013-01-22 17:13:26 +0200 | [diff] [blame] | 298 | |
Andrew M. Kuchling | a6f68e1 | 2005-06-09 14:12:36 +0000 | [diff] [blame] | 299 | def test_main(verbose=None): |
| 300 | test_support.run_unittest(TestGzip) |
| 301 | |
| 302 | if __name__ == "__main__": |
| 303 | test_main(verbose=True) |