Author rbcollins
Recipients rbcollins, yolanda.robla
Date 2016-05-12.05:13:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1463030012.4.0.290358558134.issue26807@psf.upfronthosting.co.za>
In-reply-to
Content
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
@@ -1419,6 +1419,18 @@
         self.assertEqual('abc', first)
         self.assertEqual('abc', second)

+    def test_mock_open_after_eof(self):
+        # read, readline and readlines should work after end of file.
+        _open = mock.mock_open(read_data='foo')
+        h = _open('bar')
+        h.read()
+        self.assertEqual('', h.read())
+        self.assertEqual('', h.read())
+        self.assertEqual('', h.readline())
+        self.assertEqual('', h.readline())
+        self.assertEqual([], h.readlines())
+        self.assertEqual([], h.readlines())
+
     def test_mock_parents(self):
         for Klass in Mock, MagicMock:
             m = Klass()



 ./python Lib/unittest/test/testmock/testmock.py
..........................................s........E............................
======================================================================
ERROR: test_mock_open_after_eof (__main__.MockTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/unittest/test/testmock/testmock.py", line 1430, in test_mock_open_after_eof
    self.assertEqual('', h.readline())
  File "/home/robertc/work/cpython-3.5.hg/Lib/unittest/mock.py", line 917, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/home/robertc/work/cpython-3.5.hg/Lib/unittest/mock.py", line 976, in _mock_call
    result = next(effect)
StopIteration

----------------------------------------------------------------------
Ran 80 tests in 0.197s

FAILED (errors=1, skipped=1)


That is, we need the yield '' to be infinite - while True: yield '', or the while True: to be outside the try:except.
History
Date User Action Args
2016-05-12 05:13:32rbcollinssetrecipients: + rbcollins, yolanda.robla
2016-05-12 05:13:32rbcollinssetmessageid: <1463030012.4.0.290358558134.issue26807@psf.upfronthosting.co.za>
2016-05-12 05:13:32rbcollinslinkissue26807 messages
2016-05-12 05:13:32rbcollinscreate