(self)
| 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): |
nothing calls this directly
no test coverage detected