[Python-Dev] Review of Pull Request 5974 please (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Sun Apr 29 10:26:30 EDT 2018
- Previous message (by thread): [Python-Dev] Review of Pull Request 5974 please
- Next message (by thread): [Python-Dev] Bugs Migration to OpenShift
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Reviewed. This seems to be an omission that needs to fixed, thanks for the PR! Almost good to go in 3.8. As for 3.7, this isn't a bug fix it's up to Ned if he wants to accept it.
Yury On Sun, Apr 29, 2018 at 8:02 AM Anthony Flury via Python-Dev < python-dev at python.org> wrote:
All,
Can someone please review Pull Request 5974 <https://github.com/python/cpython/pull/5974> on Python3.8 - the Pull request was submitted on 4th March - this pull request is associated with bpo-32933 <https://bugs.python.org/issue32933>
To summarize the point of this pull request:
It fixes a bug of omission within mockopen < https://docs.python.org/3/library/unittest.mock.html?highlight=mock_open#unittest.mock.mock_open
(part of unittest.mock)
The functionality of mockopen enables the test code to mock a file being opened with some data which can be read. Importantly, mockopen has a readdata attrribute which can be used to specify the data to read from the file.
The mocked file which is opened correctly supports file.read(), file.readlines(), file.readline(). These all make use of the readdata as expected, and the mocked file also supports being opened as a context manager.
But the mockopen file does not support iteration - so pythonic code which uses a for loop to iterate around the file content will only ever appear to iterate around an empty file, regardless of the readdata attribute when the mockopen is created
So non-pythonic methods to iterate around the file contents - such as this :
data = openedfile.readlines() for line in data: processline(line)
and this :
line = openedfile.readline() while line: processline(line) line = openedfile.readline()
Can both be tested with the mocked file containing simulated data (using the readdata attribute) as expected.
But this code (which by any standard is the 'correct' way to iterate around the file content of a text file):
for line in openedfile: processline(line)
Will only ever appear to iterate around an empty file when tested using mockopen.
I would like this to be reviewed so it can be back-ported into Python3.7 and 3.6 if at all possible. I know that the bug has existed since the original version of mockopen, but it does seem strange that code under test which uses a pythonic code structure can't be fully tested fully using the standard library.
-- Anthony Flury email : Anthony.flury at btinternet.com Twitter : @TonyFlury <https://twitter.com/TonyFlury/>
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/yselivanov.ml%40gmail.com
-- Yury
- Previous message (by thread): [Python-Dev] Review of Pull Request 5974 please
- Next message (by thread): [Python-Dev] Bugs Migration to OpenShift
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]