diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-05-06 13:17:52 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-05-06 13:17:52 (GMT) |
commit | 1b8a14d3f026f64ad3c2ff5eb625898d5e3491b8 (patch) | |
tree | 28400917c8f9f609ca208eeb42d21b0f2237535a /Lib | |
parent | 7e126205e615518bc921132918c0ed7f48b31c85 (diff) | |
download | cpython-1b8a14d3f026f64ad3c2ff5eb625898d5e3491b8.zip cpython-1b8a14d3f026f64ad3c2ff5eb625898d5e3491b8.tar.gz cpython-1b8a14d3f026f64ad3c2ff5eb625898d5e3491b8.tar.bz2 |
Separate tests for gzip.GzipFile and gzip.open.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_gzip.py | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index db1312d..ae9fb1b 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -33,7 +33,7 @@ class UnseekableIO(io.BytesIO): raise io.UnsupportedOperation -class TestGzip(unittest.TestCase): +class BaseTest(unittest.TestCase): filename = support.TESTFN def setUp(self): @@ -43,6 +43,7 @@ class TestGzip(unittest.TestCase): support.unlink(self.filename) +class TestGzip(BaseTest): def test_write(self): with gzip.GzipFile(self.filename, 'wb') as f: f.write(data1 * 50) @@ -115,14 +116,14 @@ class TestGzip(unittest.TestCase): # Bug #1074261 was triggered when reading a file that contained # many, many members. Create such a file and verify that reading it # works. - with gzip.open(self.filename, 'wb', 9) as f: + with gzip.GzipFile(self.filename, 'wb', 9) as f: f.write(b'a') for i in range(0, 200): - with gzip.open(self.filename, "ab", 9) as f: # append + with gzip.GzipFile(self.filename, "ab", 9) as f: # append f.write(b'a') # Try reading the file - with gzip.open(self.filename, "rb") as zgfile: + with gzip.GzipFile(self.filename, "rb") as zgfile: contents = b"" while 1: ztxt = zgfile.read(8192) @@ -374,10 +375,9 @@ class TestGzip(unittest.TestCase): datac = gzip.compress(data) self.assertEqual(gzip.decompress(datac), data) - # Test the 'open' convenience function. - def test_open_binary(self): - # Test explicit binary modes. +class TestOpen(BaseTest): + def test_binary_modes(self): uncompressed = data1 * 50 with gzip.open(self.filename, "wb") as f: f.write(uncompressed) @@ -392,7 +392,7 @@ class TestGzip(unittest.TestCase): file_data = gzip.decompress(f.read()) self.assertEqual(file_data, uncompressed * 2) - def test_open_default_binary(self): + def test_implicit_binary_modes(self): # Test implicit binary modes (no "b" or "t" in mode string). uncompressed = data1 * 50 with gzip.open(self.filename, "w") as f: @@ -408,8 +408,7 @@ class TestGzip(unittest.TestCase): file_data = gzip.decompress(f.read()) self.assertEqual(file_data, uncompressed * 2) - def test_open_text(self): - # Test text modes. + def test_text_modes(self): uncompressed = data1.decode("ascii") * 50 with gzip.open(self.filename, "wt") as f: f.write(uncompressed) @@ -424,7 +423,7 @@ class TestGzip(unittest.TestCase): file_data = gzip.decompress(f.read()).decode("ascii") self.assertEqual(file_data, uncompressed * 2) - def test_open_bad_params(self): + def test_bad_params(self): # Test invalid parameter combinations. with self.assertRaises(ValueError): gzip.open(self.filename, "wbt") @@ -435,7 +434,7 @@ class TestGzip(unittest.TestCase): with self.assertRaises(ValueError): gzip.open(self.filename, "rb", newline="\n") - def test_open_with_encoding(self): + def test_encoding(self): # Test non-default encoding. uncompressed = data1.decode("ascii") * 50 with gzip.open(self.filename, "wt", encoding="utf-16") as f: @@ -446,7 +445,7 @@ class TestGzip(unittest.TestCase): with gzip.open(self.filename, "rt", encoding="utf-16") as f: self.assertEqual(f.read(), uncompressed) - def test_open_with_encoding_error_handler(self): + def test_encoding_error_handler(self): # Test with non-default encoding error handler. with gzip.open(self.filename, "wb") as f: f.write(b"foo\xffbar") @@ -454,7 +453,7 @@ class TestGzip(unittest.TestCase): as f: self.assertEqual(f.read(), "foobar") - def test_open_with_newline(self): + def test_newline(self): # Test with explicit newline (universal newline mode disabled). uncompressed = data1.decode("ascii") * 50 with gzip.open(self.filename, "wt") as f: @@ -463,7 +462,7 @@ class TestGzip(unittest.TestCase): self.assertEqual(f.readlines(), [uncompressed]) def test_main(verbose=None): - support.run_unittest(TestGzip) + support.run_unittest(TestGzip, TestOpen) if __name__ == "__main__": test_main(verbose=True) |