Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9549a3e3
Commit
9549a3e3
authored
May 16, 2016
by
Robert Collins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
parent
33a8fb99
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
0 deletions
+18
-0
Lib/unittest/mock.py
Lib/unittest/mock.py
+2
-0
Lib/unittest/test/testmock/testmock.py
Lib/unittest/test/testmock/testmock.py
+12
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/mock.py
View file @
9549a3e3
...
...
@@ -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
...
...
Lib/unittest/test/testmock/testmock.py
View file @
9549a3e3
...
...
@@ -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()
...
...
Misc/ACKS
View file @
9549a3e3
...
...
@@ -1223,6 +1223,7 @@ Ben Roberts
Mark Roberts
Andy Robinson
Jim Robinson
Yolanda Robla
Daniel Rocco
Mark Roddy
Kevin Rodgers
...
...
Misc/NEWS
View file @
9549a3e3
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment