diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-10 18:28:07 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-10 18:28:07 (GMT) |
commit | b0d497c0726c118d40dfadea807b32077f067100 (patch) | |
tree | 4f4d8502ad09d2197f22d0e86b3c2635fe1ce739 /Lib/test/test_zipfile.py | |
parent | b32e869eb1f63907c54aacf725601d637f1171c1 (diff) | |
download | cpython-b0d497c0726c118d40dfadea807b32077f067100.zip cpython-b0d497c0726c118d40dfadea807b32077f067100.tar.gz cpython-b0d497c0726c118d40dfadea807b32077f067100.tar.bz2 |
Issue #24693: Changed some RuntimeError's in the zipfile module to more
appropriate types. Improved some error messages and debugging output.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r-- | Lib/test/test_zipfile.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index ef3c3d8..ff4a6d6 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -449,15 +449,15 @@ class StoredTestsWithSourceFile(AbstractTestsWithSourceFile, def test_write_to_readonly(self): """Check that trying to call write() on a readonly ZipFile object - raises a RuntimeError.""" + raises a ValueError.""" with zipfile.ZipFile(TESTFN2, mode="w") as zipfp: zipfp.writestr("somefile.txt", "bogus") with zipfile.ZipFile(TESTFN2, mode="r") as zipfp: - self.assertRaises(RuntimeError, zipfp.write, TESTFN) + self.assertRaises(ValueError, zipfp.write, TESTFN) with zipfile.ZipFile(TESTFN2, mode="r") as zipfp: - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipfp.open(TESTFN, mode='w') def test_add_file_before_1980(self): @@ -1210,27 +1210,27 @@ class OtherTests(unittest.TestCase): fp.write("short file") self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN) - def test_closed_zip_raises_RuntimeError(self): + def test_closed_zip_raises_ValueError(self): """Verify that testzip() doesn't swallow inappropriate exceptions.""" data = io.BytesIO() with zipfile.ZipFile(data, mode="w") as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") # This is correct; calling .read on a closed ZipFile should raise - # a RuntimeError, and so should calling .testzip. An earlier + # a ValueError, and so should calling .testzip. An earlier # version of .testzip would swallow this exception (and any other) # and report that the first file in the archive was corrupt. - self.assertRaises(RuntimeError, zipf.read, "foo.txt") - self.assertRaises(RuntimeError, zipf.open, "foo.txt") - self.assertRaises(RuntimeError, zipf.testzip) - self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus") + self.assertRaises(ValueError, zipf.read, "foo.txt") + self.assertRaises(ValueError, zipf.open, "foo.txt") + self.assertRaises(ValueError, zipf.testzip) + self.assertRaises(ValueError, zipf.writestr, "bogus.txt", "bogus") with open(TESTFN, 'w') as f: f.write('zipfile test data') - self.assertRaises(RuntimeError, zipf.write, TESTFN) + self.assertRaises(ValueError, zipf.write, TESTFN) def test_bad_constructor_mode(self): """Check that bad modes passed to ZipFile constructor are caught.""" - self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "q") + self.assertRaises(ValueError, zipfile.ZipFile, TESTFN, "q") def test_bad_open_mode(self): """Check that bad modes passed to ZipFile.open are caught.""" @@ -1240,10 +1240,10 @@ class OtherTests(unittest.TestCase): with zipfile.ZipFile(TESTFN, mode="r") as zipf: # read the data to make sure the file is there zipf.read("foo.txt") - self.assertRaises(RuntimeError, zipf.open, "foo.txt", "q") + self.assertRaises(ValueError, zipf.open, "foo.txt", "q") # universal newlines support is removed - self.assertRaises(RuntimeError, zipf.open, "foo.txt", "U") - self.assertRaises(RuntimeError, zipf.open, "foo.txt", "rU") + self.assertRaises(ValueError, zipf.open, "foo.txt", "U") + self.assertRaises(ValueError, zipf.open, "foo.txt", "rU") def test_read0(self): """Check that calling read(0) on a ZipExtFile object returns an empty @@ -1266,7 +1266,7 @@ class OtherTests(unittest.TestCase): def test_bad_compression_mode(self): """Check that bad compression methods passed to ZipFile.open are caught.""" - self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1) + self.assertRaises(NotImplementedError, zipfile.ZipFile, TESTFN, "w", -1) def test_unsupported_compression(self): # data is declared as shrunk, but actually deflated @@ -1423,15 +1423,15 @@ class OtherTests(unittest.TestCase): with zipf.open('foo', mode='w') as w2: w2.write(msg1) with zipf.open('bar', mode='w') as w1: - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.open('handle', mode='w') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.open('foo', mode='r') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.writestr('str', 'abcde') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.write(__file__, 'file') - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): zipf.close() w1.write(msg2) with zipf.open('baz', mode='w') as w2: |