diff options
author | Damien Nadé <Anvil@users.noreply.github.com> | 2019-05-23 12:03:25 +0200 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-23 03:03:25 -0700 |
commit | 394119afc6611f17bac96f5ec6fefa00000ae795 (patch) | |
tree | 27fc4f991110ed5d3bf09bb0e3e3051b6eddcc91 /Lib/unittest/mock.py | |
parent | 51aa35e9e17eef60d04add9619fe2a7eb938358c (diff) | |
download | cpython-git-394119afc6611f17bac96f5ec6fefa00000ae795.tar.gz |
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
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 654462cbf7..b14bf01b28 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -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) |