aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/unittest/test/testmock/testwith.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/testwith.py
parent51aa35e9e17eef60d04add9619fe2a7eb938358c (diff)
downloadcpython-394119afc6611f17bac96f5ec6fefa00000ae795.tar.gz
cpython-394119afc6611f17bac96f5ec6fefa00000ae795.zip
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/testwith.py')
-rw-r--r--Lib/unittest/test/testmock/testwith.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py
index 5172c222d97..42ebf3898c8 100644
--- a/Lib/unittest/test/testmock/testwith.py
+++ b/Lib/unittest/test/testmock/testwith.py
@@ -230,7 +230,22 @@ class TestMockOpen(unittest.TestCase):
self.assertEqual(lines[1], 'bar\n')
self.assertEqual(lines[2], 'baz\n')
self.assertEqual(h.readline(), '')
+ with self.assertRaises(StopIteration):
+ next(h)
+ def test_next_data(self):
+ # Check that next will correctly return the next available
+ # line and plays well with the dunder_iter part.
+ mock = mock_open(read_data='foo\nbar\nbaz\n')
+ with patch('%s.open' % __name__, mock, create=True):
+ h = open('bar')
+ line1 = next(h)
+ line2 = next(h)
+ lines = [l for l in h]
+ self.assertEqual(line1, 'foo\n')
+ self.assertEqual(line2, 'bar\n')
+ self.assertEqual(lines[0], 'baz\n')
+ self.assertEqual(h.readline(), '')
def test_readlines_data(self):
# Test that emulating a file that ends in a newline character works