Message312706
Using the unittest.mock helper mock_open with multi-line read data, although readlines method will work on the mocked open data, the commonly used iterator idiom on an open file returns the equivalent of an empty file.
from unittest.mock import mock_open
read_data = 'line 1\nline 2\nline 3\nline 4\n'
with patch('builtins.open', mock_open) as mocked:
with open('a.txt', 'r') as fp:
assert [l for l in StringIO(read_data)] ==
[l for l in fp]
will fail although it will work on a normal file with the same data, and using [l for l in fp.readlines()] will also work.
There is a relatively simple fix which I have a working local version - but I don't know how to provide that back to the library - or even if i should. |
|
Date |
User |
Action |
Args |
2018-02-24 08:58:38 | anthony-flury | set | recipients:
+ anthony-flury |
2018-02-24 08:58:38 | anthony-flury | set | messageid: <1519462718.87.0.467229070634.issue32933@psf.upfronthosting.co.za> |
2018-02-24 08:58:38 | anthony-flury | link | issue32933 messages |
2018-02-24 08:58:38 | anthony-flury | create | |
|