[issue26807] mock_open()().readline() fails at EOF

2016-05-15 Thread Robert Collins
Robert Collins added the comment: I've committed a minimal variation - thanks for the patches. -- resolution: -> fixed stage: test needed -> resolved status: open -> closed ___ Python tracker

[issue26807] mock_open()().readline() fails at EOF

2016-05-15 Thread Roundup Robot
Roundup Robot added the comment: New changeset cbb31b2a3dba by Robert Collins in branch '3.5': Issue #26807: mock_open 'files' no longer error on readline at end of file. https://hg.python.org/cpython/rev/cbb31b2a3dba New changeset 72a798e27117 by Robert Collins in branch 'default': Issue

[issue26807] mock_open()().readline() fails at EOF

2016-05-12 Thread Robert Collins
Robert Collins added the comment: So something like for line in _state[0]: yield line while True: yield '' Will probably do it just fine. -- ___ Python tracker

[issue26807] mock_open()().readline() fails at EOF

2016-05-11 Thread Robert Collins
Robert Collins added the comment: Actually, further inspection and a teddybear with Angus Lees uncovers this: diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py

[issue26807] mock_open()().readline() fails at EOF

2016-05-11 Thread Robert Collins
Robert Collins added the comment: ./python Lib/unittest/test/testmock/testmock.py ..s. -- Ran 80 tests in 0.180s OK (skipped=1) So thats great. I am

[issue26807] mock_open()().readline() fails at EOF

2016-04-30 Thread Yolanda
Yolanda added the comment: How about... @@ -2339,9 +2339,12 @@ def mock_open(mock=None, read_data=''): if handle.readline.return_value is not None: while True: yield handle.readline.return_value -for line in _state[0]: -yield line +

[issue26807] mock_open()().readline() fails at EOF

2016-04-26 Thread Yolanda
Yolanda added the comment: I tried patching the readline_side_effect call. But i cannot trap StopIteration there, and i don't see any clear way to detect that the generator has reached its end at that level. -- ___ Python tracker

[issue26807] mock_open()().readline() fails at EOF

2016-04-25 Thread Robert Collins
Robert Collins added the comment: You're changing _mock_call but readline is actually implemented in _readline_side_effect - just changing that should be all thats needed (to deal with StopIteration). You will however need to fixup the return values since the test I added is a bit wider than

[issue26807] mock_open()().readline() fails at EOF

2016-04-25 Thread Yolanda
Yolanda added the comment: So... the failures are because i'm capturing the StopIteration exception in that case. then it's normal that it's not raised. How should you solve that problem instead? -- ___ Python tracker

[issue26807] mock_open()().readline() fails at EOF

2016-04-25 Thread Robert Collins
Robert Collins added the comment: Thanks Yolanda. I've touched up the test a little and run a full test run (make test) - sadly it fails: there is an explicit test that StopIteration gets raised if you set it as a side effect.

[issue26807] mock_open()().readline() fails at EOF

2016-04-25 Thread Yolanda
Yolanda added the comment: diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py index a7bee73..efe6391 100644 --- a/Lib/unittest/test/testmock/testwith.py +++ b/Lib/unittest/test/testmock/testwith.py @@ -297,5 +297,16 @@ class

[issue26807] mock_open()().readline() fails at EOF

2016-04-22 Thread Robert Collins
Robert Collins added the comment: Thanks Yolanda, that looks sane - could you perhaps add a test for this in Lib/unittest/tests/test_mock/ ? -- ___ Python tracker

[issue26807] mock_open()().readline() fails at EOF

2016-04-20 Thread Yolanda
Yolanda added the comment: diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 7400fb7..9e47cd2 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -991,7 +991,10 @@ class CallableMixin(Base): raise effect if not _callable(effect): -

[issue26807] mock_open()().readline() fails at EOF

2016-04-20 Thread Robert Collins
New submission from Robert Collins: >>> import unittest.mock >>> o = unittest.mock.mock_open(read_data="fred") >>> f = o() >>> f.read() 'fred' >>> f.read() '' >>> f.readlines() [] >>> f.readline() Traceback (most recent call last): File "", line 1, in File