Issue #26807: mock_open 'files' no longer error on readline at end of file.

Patch from Yolanda Robla.
This commit is contained in:
Robert Collins 2016-05-16 15:22:01 +12:00
parent 33a8fb9920
commit 9549a3e3d4
4 changed files with 18 additions and 0 deletions

View File

@ -2323,6 +2323,8 @@ def mock_open(mock=None, read_data=''):
yield handle.readline.return_value
for line in _state[0]:
yield line
while True:
yield type(read_data)()
global file_spec

View File

@ -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()

View File

@ -1223,6 +1223,7 @@ Ben Roberts
Mark Roberts
Andy Robinson
Jim Robinson
Yolanda Robla
Daniel Rocco
Mark Roddy
Kevin Rodgers

View File

@ -124,6 +124,9 @@ Library
- Issue #22274: In the subprocess module, allow stderr to be redirected to
stdout even when stdout is not redirected. Patch by Akira Li.
- Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
- Issue #25745: Fixed leaking a userptr in curses panel destructor.
- Issue #26977: Removed unnecessary, and ignored, call to sum of squares helper