summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2016-06-08 17:47:26 -0400
committerBarry Warsaw <barry@python.org>2016-06-08 17:47:26 -0400
commit54512b6e84565c83e19bcf94d186fd533e92445b (patch)
treedc0891ebc19ad0af99b4612cfcb5c820591e2363 /Lib/test
parent67178c64e0e544aac96bf44ac13812fea7b32157 (diff)
downloadcpython-54512b6e84565c83e19bcf94d186fd533e92445b.tar.gz
Issue #27066: Fixed SystemError if a custom opener (for open()) returns
a negative number without setting an exception.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_io.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 73231981ad..000b525003 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -805,6 +805,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, \