mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-37008: make mock_open handle able to honor next() (GH-13492)
I've reported the issue on https://bugs.python.org/issue37008 and now I'm trying to bring a solution to this minor issue. I think it could be trivially backported to 3.7 branch. https://bugs.python.org/issue37008
This commit is contained in:
parent
51aa35e9e1
commit
394119afc6
4 changed files with 36 additions and 0 deletions
|
@ -1702,6 +1702,19 @@ class MockTest(unittest.TestCase):
|
|||
self.assertEqual(lines[1], 'Norwegian Blue')
|
||||
self.assertEqual(list(f1), [])
|
||||
|
||||
def test_mock_open_using_next(self):
|
||||
mocked_open = mock.mock_open(read_data='1st line\n2nd line\n3rd line')
|
||||
f1 = mocked_open('a-name')
|
||||
line1 = next(f1)
|
||||
line2 = f1.__next__()
|
||||
lines = [line for line in f1]
|
||||
self.assertEqual(line1, '1st line\n')
|
||||
self.assertEqual(line2, '2nd line\n')
|
||||
self.assertEqual(lines[0], '3rd line')
|
||||
self.assertEqual(list(f1), [])
|
||||
with self.assertRaises(StopIteration):
|
||||
next(f1)
|
||||
|
||||
def test_mock_open_write(self):
|
||||
# Test exception in file writing write()
|
||||
mock_namedtemp = mock.mock_open(mock.MagicMock(name='JLV'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue