[issue21258] Add __iter__ support for mock_open

2018-09-12 Thread Berker Peksag


Berker Peksag  added the comment:

Closing this as a duplicate of issue 32933. Let's discuss backporting to 
maintenance branches there.

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> mock_open does not support iteration around text files.

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2018-09-12 Thread Anthony Flury


Anthony Flury  added the comment:

The lack of dunder_iter support on mock_open has been resolved in Issue 32933 
(Git Hub 5974).

Can I suggest that once the above PR is merged into 3.8 (due imminently 
allegedly ), that we should then backport that fix into 3.5, 3.6 & 3.7 
as a minimum ?

I am by no means an expert though.

--
nosy: +anthony-flury

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2018-02-15 Thread Lumír Balhar

Change by Lumír Balhar :


--
nosy: +frenzy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2017-01-15 Thread Georg Sauthoff

Georg Sauthoff added the comment:

For working around this issue on Python 3.5 it is sufficient to overwrite just 
the `return_value.__iter__` method of the object returned by `mock_open()` with 
an iterator that calls the mocked `readline()` method until it returns the 
empty string.

cf. e.g. 
https://github.com/gsauthof/utility/blob/6489c7215dac341be4e40e5348e64d69461766dd/user-installed.py#L176-L179

This also works in combination with `csv.reader()`, i.e. when calling it with 
the mocked file object.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2017-01-15 Thread Georg Sauthoff

Changes by Georg Sauthoff :


--
nosy: +gms

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2015-12-14 Thread José Luis Lafuente

Changes by José Luis Lafuente :


--
nosy: +José.Luis.Lafuente

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2015-07-17 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +berker.peksag
versions: +Python 3.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2015-01-29 Thread Maciej Zagrabski

Maciej Zagrabski added the comment:

Provided path did not work for me. Probably because lack of __next__ handler. I 
noticed that issue when interacting with cvs.reader and cvs.DictReader. After 
simple modification it seems to work fine.

--
nosy: +mucka
versions: +Python 3.4
Added file: http://bugs.python.org/file37908/mock_new.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2014-07-04 Thread Arve Knudsen

Changes by Arve Knudsen arve.knud...@gmail.com:


--
nosy: +Arve.Knudsen

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2014-07-04 Thread Arve Knudsen

Arve Knudsen added the comment:

I noticed this issue too, thanks for fixing it!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2014-06-12 Thread Paul Koning

Paul Koning added the comment:

I created a fix for this.  This also fixes a second issue in mock_open, which 
is that readline() raises StopIteration at EOF rather than returning empty 
strings.  See attached diff.
(Is there a  better procedure for submitting fixes?)

--
nosy: +pkoning
Added file: http://bugs.python.org/file35597/mock.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2014-06-12 Thread Paul Koning

Paul Koning added the comment:

This is the corresponding patch to the test suite.

--
Added file: http://bugs.python.org/file35598/testwith.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21258] Add __iter__ support for mock_open

2014-04-16 Thread Michael Foord

New submission from Michael Foord:

mock_open returns a mock object suitable for using as a mock file handle. File 
handles support iteration, so mock_open should support that. If possible it 
should be integrated with the current read/readlines support (only if 
possible), so the suggested patch may not be enough.


1.Want to mock this:
with open(source_file, 'r') as f: 
for line_num, line_text in enumerate(f):
print line_text

2.  Tried this:
with patch('__builtin__.open', mock_open(read_data='text'), create=True) as p:

3.  enumerate causes a call to __iter__() which is not handled by the mock_open 
code.


What is the expected output? What do you see instead?

The __iter__ is allowed on the returned file handle

What version of the product are you using? On what operating system?

latest

Please provide any additional information below.

Patch would have mock_open setup handle.__iter__.return_value to a passed in 
parm or if none, possibly a iter(StringIO(read_data)) on the existing read_data 
parm to keep the interface unchanged.

--
assignee: michael.foord
components: Library (Lib)
files: 213.patch
keywords: patch
messages: 216522
nosy: kushal.das, michael.foord
priority: normal
severity: normal
stage: patch review
status: open
title: Add __iter__ support for mock_open
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file34917/213.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21258
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com