diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-12 08:52:35 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-12 08:52:35 (GMT) |
commit | 61e2493b8341be74928872ce6d7fb3a350bd1697 (patch) | |
tree | a9e16cf785c8cd4c54d79c633e11fa64c9857672 /Lib | |
parent | 1f9d11b986c95005fbebb724ee3425ad2eb30967 (diff) | |
download | cpython-61e2493b8341be74928872ce6d7fb3a350bd1697.zip cpython-61e2493b8341be74928872ce6d7fb3a350bd1697.tar.gz cpython-61e2493b8341be74928872ce6d7fb3a350bd1697.tar.bz2 |
Issue #17671: Fixed a crash when use non-initialized io.BufferedRWPair.
Based on patch by Stephen Tu.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 5c2c79b..ac6d478 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -846,6 +846,16 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): bufio.__init__(rawio) self.assertEqual(b"abc", bufio.read()) + def test_uninitialized(self): + bufio = self.tp.__new__(self.tp) + del bufio + bufio = self.tp.__new__(self.tp) + self.assertRaisesRegex((ValueError, AttributeError), + 'uninitialized|has no attribute', + bufio.read, 0) + bufio.__init__(self.MockRawIO()) + self.assertEqual(bufio.read(0), b'') + def test_read(self): for arg in (None, 7): rawio = self.MockRawIO((b"abc", b"d", b"efg")) @@ -1096,6 +1106,16 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests): bufio.flush() self.assertEqual(b"".join(rawio._write_stack), b"abcghi") + def test_uninitialized(self): + bufio = self.tp.__new__(self.tp) + del bufio + bufio = self.tp.__new__(self.tp) + self.assertRaisesRegex((ValueError, AttributeError), + 'uninitialized|has no attribute', + bufio.write, b'') + bufio.__init__(self.MockRawIO()) + self.assertEqual(bufio.write(b''), 0) + def test_detach_flush(self): raw = self.MockRawIO() buf = self.tp(raw) @@ -1379,6 +1399,20 @@ class BufferedRWPairTest(unittest.TestCase): pair = self.tp(self.MockRawIO(), self.MockRawIO()) self.assertFalse(pair.closed) + def test_uninitialized(self): + pair = self.tp.__new__(self.tp) + del pair + pair = self.tp.__new__(self.tp) + self.assertRaisesRegex((ValueError, AttributeError), + 'uninitialized|has no attribute', + pair.read, 0) + self.assertRaisesRegex((ValueError, AttributeError), + 'uninitialized|has no attribute', + pair.write, b'') + pair.__init__(self.MockRawIO(), self.MockRawIO()) + self.assertEqual(pair.read(0), b'') + self.assertEqual(pair.write(b''), 0) + def test_detach(self): pair = self.tp(self.MockRawIO(), self.MockRawIO()) self.assertRaises(self.UnsupportedOperation, pair.detach) @@ -1505,6 +1539,10 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest): BufferedReaderTest.test_constructor(self) BufferedWriterTest.test_constructor(self) + def test_uninitialized(self): + BufferedReaderTest.test_uninitialized(self) + BufferedWriterTest.test_uninitialized(self) + def test_read_and_write(self): raw = self.MockRawIO((b"asdf", b"ghjk")) rw = self.tp(raw, 8) |