Message265362
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. | |
| Date | User | Action | Args | | 2016-05-12 05:13:32 | rbcollins | set | recipients: + rbcollins, yolanda.robla | | 2016-05-12 05:13:32 | rbcollins | set | messageid: <1463030012.4.0.290358558134.issue26807@psf.upfronthosting.co.za> | | 2016-05-12 05:13:32 | rbcollins | link | issue26807 messages | | 2016-05-12 05:13:32 | rbcollins | create | | |