summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/testmock/testmock.py
diff options
context:
space:
mode:
authorDamien Nadé <Anvil@users.noreply.github.com>2019-05-23 12:03:25 +0200
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-23 03:03:25 -0700
commit394119afc6611f17bac96f5ec6fefa00000ae795 (patch)
tree27fc4f991110ed5d3bf09bb0e3e3051b6eddcc91 /Lib/unittest/test/testmock/testmock.py
parent51aa35e9e17eef60d04add9619fe2a7eb938358c (diff)
downloadcpython-git-394119afc6611f17bac96f5ec6fefa00000ae795.tar.gz
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
Diffstat (limited to 'Lib/unittest/test/testmock/testmock.py')
-rw-r--r--Lib/unittest/test/testmock/testmock.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 307b8b7657..0f30bccc9c 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -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'))