summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2016-05-16 03:22:01 (GMT)
committerRobert Collins <rbtcollins@hp.com>2016-05-16 03:22:01 (GMT)
commit9549a3e3d4be2a15c222996abff8cb97180ee9be (patch)
tree6459b7352282cce393976499fa5830aa14b9d96c /Lib/unittest/test
parent33a8fb9920efc4e4f8c6afa1062c966b27f222a9 (diff)
downloadcpython-9549a3e3d4be2a15c222996abff8cb97180ee9be.zip
cpython-9549a3e3d4be2a15c222996abff8cb97180ee9be.tar.gz
cpython-9549a3e3d4be2a15c222996abff8cb97180ee9be.tar.bz2
Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/testmock/testmock.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 03c95de..5f82b82 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -1419,6 +1419,18 @@ class MockTest(unittest.TestCase):
self.assertEqual('abc', first)
self.assertEqual('abc', second)
+ def test_mock_open_after_eof(self):
+ # read, readline and readlines should work after end of file.
+ _open = mock.mock_open(read_data='foo')
+ h = _open('bar')
+ h.read()
+ self.assertEqual('', h.read())
+ self.assertEqual('', h.read())
+ self.assertEqual('', h.readline())
+ self.assertEqual('', h.readline())
+ self.assertEqual([], h.readlines())
+ self.assertEqual([], h.readlines())
+
def test_mock_parents(self):
for Klass in Mock, MagicMock:
m = Klass()