MCPcopy Index your code
hub / github.com/python/cpython / test_readline_data

Method test_readline_data

Lib/test/test_unittest/testmock/testwith.py:200–220  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

198
199
200 def test_readline_data(self):
201 # Check that readline will return all the lines from the fake file
202 # And that once fully consumed, readline will return an empty string.
203 mock = mock_open(read_data='foo\nbar\nbaz\n')
204 with patch('%s.open' % __name__, mock, create=True):
205 h = open('bar')
206 line1 = h.readline()
207 line2 = h.readline()
208 line3 = h.readline()
209 self.assertEqual(line1, 'foo\n')
210 self.assertEqual(line2, 'bar\n')
211 self.assertEqual(line3, 'baz\n')
212 self.assertEqual(h.readline(), '')
213
214 # Check that we properly emulate a file that doesn't end in a newline
215 mock = mock_open(read_data='foo')
216 with patch('%s.open' % __name__, mock, create=True):
217 h = open('bar')
218 result = h.readline()
219 self.assertEqual(result, 'foo')
220 self.assertEqual(h.readline(), '')
221
222
223 def test_dunder_iter_data(self):

Callers

nothing calls this directly

Calls 5

mock_openFunction · 0.90
patchFunction · 0.90
openFunction · 0.50
readlineMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected