[3.7] bpo-32933: Implement __iter__ method on mock_open() (GH-5974) by miss-islington · Pull Request #9311 · python/cpython
Expand Up
@@ -188,6 +188,7 @@ def test_read_data(self):
def test_readline_data(self): # Check that readline will return all the lines from the fake file # And that once fully consumed, readline will return an empty string. mock = mock_open(read_data='foo\nbar\nbaz\n') with patch('%s.open' % __name__, mock, create=True): h = open('bar') Expand All @@ -197,13 +198,27 @@ def test_readline_data(self): self.assertEqual(line1, 'foo\n') self.assertEqual(line2, 'bar\n') self.assertEqual(line3, 'baz\n') self.assertEqual(h.readline(), '')
# Check that we properly emulate a file that doesn't end in a newline mock = mock_open(read_data='foo') with patch('%s.open' % __name__, mock, create=True): h = open('bar') result = h.readline() self.assertEqual(result, 'foo') self.assertEqual(h.readline(), '')
def test_dunder_iter_data(self): # Check that dunder_iter will return all the lines from the fake file. mock = mock_open(read_data='foo\nbar\nbaz\n') with patch('%s.open' % __name__, mock, create=True): h = open('bar') lines = [l for l in h] self.assertEqual(lines[0], 'foo\n') self.assertEqual(lines[1], 'bar\n') self.assertEqual(lines[2], 'baz\n') self.assertEqual(h.readline(), '')
def test_readlines_data(self): Expand Down
def test_readline_data(self): # Check that readline will return all the lines from the fake file # And that once fully consumed, readline will return an empty string. mock = mock_open(read_data='foo\nbar\nbaz\n') with patch('%s.open' % __name__, mock, create=True): h = open('bar') Expand All @@ -197,13 +198,27 @@ def test_readline_data(self): self.assertEqual(line1, 'foo\n') self.assertEqual(line2, 'bar\n') self.assertEqual(line3, 'baz\n') self.assertEqual(h.readline(), '')
# Check that we properly emulate a file that doesn't end in a newline mock = mock_open(read_data='foo') with patch('%s.open' % __name__, mock, create=True): h = open('bar') result = h.readline() self.assertEqual(result, 'foo') self.assertEqual(h.readline(), '')
def test_dunder_iter_data(self): # Check that dunder_iter will return all the lines from the fake file. mock = mock_open(read_data='foo\nbar\nbaz\n') with patch('%s.open' % __name__, mock, create=True): h = open('bar') lines = [l for l in h] self.assertEqual(lines[0], 'foo\n') self.assertEqual(lines[1], 'bar\n') self.assertEqual(lines[2], 'baz\n') self.assertEqual(h.readline(), '')
def test_readlines_data(self): Expand Down