Issue #10750: The raw attribute of buffered IO objects is now read-only.

This commit is contained in:
Antoine Pitrou 2010-12-21 21:20:59 +00:00
parent cfee0e83eb
commit 7f8f41808b
4 changed files with 32 additions and 9 deletions

View file

@ -730,6 +730,13 @@ class CommonBufferedTests:
self.assertRaises(self.UnsupportedOperation, bufio.tell)
self.assertRaises(self.UnsupportedOperation, bufio.seek, 0)
def test_readonly_attributes(self):
raw = self.MockRawIO()
buf = self.tp(raw)
x = self.MockRawIO()
with self.assertRaises(AttributeError):
buf.raw = x
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
read_mode = "rb"
@ -2245,6 +2252,12 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertRaises(self.UnsupportedOperation, txt.tell)
self.assertRaises(self.UnsupportedOperation, txt.seek, 0)
def test_readonly_attributes(self):
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
buf = self.BytesIO(self.testdata)
with self.assertRaises(AttributeError):
txt.buffer = buf
class CTextIOWrapperTest(TextIOWrapperTest):
def test_initialization(self):