mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37008: make mock_open handle able to honor next() (GH-13492)
I've reported the issue on https://bugs.python.org/issue37008 and now I'm trying to bring a solution to this minor issue. I think it could be trivially backported to 3.7 branch. https://bugs.python.org/issue37008
This commit is contained in:
parent
51aa35e9e1
commit
394119afc6
4 changed files with 36 additions and 0 deletions
|
@ -2680,6 +2680,11 @@ def mock_open(mock=None, read_data=''):
|
|||
for line in _state[0]:
|
||||
yield line
|
||||
|
||||
def _next_side_effect():
|
||||
if handle.readline.return_value is not None:
|
||||
return handle.readline.return_value
|
||||
return next(_state[0])
|
||||
|
||||
global file_spec
|
||||
if file_spec is None:
|
||||
import _io
|
||||
|
@ -2701,6 +2706,7 @@ def mock_open(mock=None, read_data=''):
|
|||
handle.readline.side_effect = _state[1]
|
||||
handle.readlines.side_effect = _readlines_side_effect
|
||||
handle.__iter__.side_effect = _iter_side_effect
|
||||
handle.__next__.side_effect = _next_side_effect
|
||||
|
||||
def reset_data(*args, **kwargs):
|
||||
_state[0] = _to_stream(read_data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue