changeset: 101354:72a798e27117 parent: 101352:5b5a16132051 parent: 101353:cbb31b2a3dba user: Robert Collins date: Mon May 16 15:22:45 2016 +1200 files: Lib/unittest/mock.py Lib/unittest/test/testmock/testmock.py Misc/ACKS Misc/NEWS description: Issue #26807: mock_open 'files' no longer error on readline at end of file. Patch from Yolanda Robla. diff -r 5b5a16132051 -r 72a798e27117 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sun May 15 22:07:12 2016 -0400 +++ b/Lib/unittest/mock.py Mon May 16 15:22:45 2016 +1200 @@ -2341,6 +2341,8 @@ yield handle.readline.return_value for line in _state[0]: yield line + while True: + yield type(read_data)() global file_spec diff -r 5b5a16132051 -r 72a798e27117 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Sun May 15 22:07:12 2016 -0400 +++ b/Lib/unittest/test/testmock/testmock.py Mon May 16 15:22:45 2016 +1200 @@ -1440,6 +1440,18 @@ 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() diff -r 5b5a16132051 -r 72a798e27117 Misc/ACKS --- a/Misc/ACKS Sun May 15 22:07:12 2016 -0400 +++ b/Misc/ACKS Mon May 16 15:22:45 2016 +1200 @@ -1231,6 +1231,7 @@ Mark Roberts Andy Robinson Jim Robinson +Yolanda Robla Daniel Rocco Mark Roddy Kevin Rodgers diff -r 5b5a16132051 -r 72a798e27117 Misc/NEWS --- a/Misc/NEWS Sun May 15 22:07:12 2016 -0400 +++ b/Misc/NEWS Mon May 16 15:22:45 2016 +1200 @@ -290,6 +290,9 @@ - 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