diff options
author | Barry Warsaw <barry@python.org> | 2016-06-08 21:54:43 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2016-06-08 21:54:43 (GMT) |
commit | 118598a072be1ec8d6cbc3636cd514538a868152 (patch) | |
tree | f35b2737564ff02ecd3e9211ec9f27db550d9d45 /Lib | |
parent | 24f3a1829fe007915a93e9515cd28470dd8a00d9 (diff) | |
parent | 480e28538d42b9cf8e8b2163bfa9e23e27b80793 (diff) | |
download | cpython-118598a072be1ec8d6cbc3636cd514538a868152.zip cpython-118598a072be1ec8d6cbc3636cd514538a868152.tar.gz cpython-118598a072be1ec8d6cbc3636cd514538a868152.tar.bz2 |
Issue #27066: Fixed SystemError if a custom opener (for open()) returns a
negative number without setting an exception.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 5584d6b..8581865 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -809,6 +809,22 @@ class IOTest(unittest.TestCase): with self.open("non-existent", "r", opener=opener) as f: self.assertEqual(f.read(), "egg\n") + def test_bad_opener_negative_1(self): + # Issue #27066. + def badopener(fname, flags): + return -1 + with self.assertRaises(ValueError) as cm: + open('non-existent', 'r', opener=badopener) + self.assertEqual(str(cm.exception), 'opener returned -1') + + def test_bad_opener_other_negative(self): + # Issue #27066. + def badopener(fname, flags): + return -2 + with self.assertRaises(ValueError) as cm: + open('non-existent', 'r', opener=badopener) + self.assertEqual(str(cm.exception), 'opener returned -2') + def test_fileio_closefd(self): # Issue #4841 with self.open(__file__, 'rb') as f1, \ |