bpo-32933: Implement iter method on mock_open() (GH-5974) · python/cpython@c83c375 (original) (raw)

`@@ -188,6 +188,7 @@ def test_read_data(self):

`

188

188

``

189

189

`def test_readline_data(self):

`

190

190

`# Check that readline will return all the lines from the fake file

`

``

191

`+

And that once fully consumed, readline will return an empty string.

`

191

192

`mock = mock_open(read_data='foo\nbar\nbaz\n')

`

192

193

`with patch('%s.open' % name, mock, create=True):

`

193

194

`h = open('bar')

`

`@@ -197,13 +198,27 @@ def test_readline_data(self):

`

197

198

`self.assertEqual(line1, 'foo\n')

`

198

199

`self.assertEqual(line2, 'bar\n')

`

199

200

`self.assertEqual(line3, 'baz\n')

`

``

201

`+

self.assertEqual(h.readline(), '')

`

200

202

``

201

203

`# Check that we properly emulate a file that doesn't end in a newline

`

202

204

`mock = mock_open(read_data='foo')

`

203

205

`with patch('%s.open' % name, mock, create=True):

`

204

206

`h = open('bar')

`

205

207

`result = h.readline()

`

206

208

`self.assertEqual(result, 'foo')

`

``

209

`+

self.assertEqual(h.readline(), '')

`

``

210

+

``

211

+

``

212

`+

def test_dunder_iter_data(self):

`

``

213

`+

Check that dunder_iter will return all the lines from the fake file.

`

``

214

`+

mock = mock_open(read_data='foo\nbar\nbaz\n')

`

``

215

`+

with patch('%s.open' % name, mock, create=True):

`

``

216

`+

h = open('bar')

`

``

217

`+

lines = [l for l in h]

`

``

218

`+

self.assertEqual(lines[0], 'foo\n')

`

``

219

`+

self.assertEqual(lines[1], 'bar\n')

`

``

220

`+

self.assertEqual(lines[2], 'baz\n')

`

``

221

`+

self.assertEqual(h.readline(), '')

`

207

222

``

208

223

``

209

224

`def test_readlines_data(self):

`