@@ -188,6 +188,7 @@ def test_read_data(self):
188188
189189 def test_readline_data (self ):
190190 # Check that readline will return all the lines from the fake file
191+ # And that once fully consumed, readline will return an empty string.
191192 mock = mock_open (read_data = 'foo\n bar\n baz\n ' )
192193 with patch ('%s.open' % __name__ , mock , create = True ):
193194 h = open ('bar' )
@@ -197,13 +198,27 @@ def test_readline_data(self):
197198 self .assertEqual (line1 , 'foo\n ' )
198199 self .assertEqual (line2 , 'bar\n ' )
199200 self .assertEqual (line3 , 'baz\n ' )
201+ self .assertEqual (h .readline (), '' )
200202
201203 # Check that we properly emulate a file that doesn't end in a newline
202204 mock = mock_open (read_data = 'foo' )
203205 with patch ('%s.open' % __name__ , mock , create = True ):
204206 h = open ('bar' )
205207 result = h .readline ()
206208 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\n bar\n baz\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 (), '' )
207222
208223
209224 def test_readlines_data (self ):
0 commit comments