@@ -351,6 +351,7 @@ def test_empty_files_list_specified_to_constructor(self):
351351 with FileInput (files = []) as fi :
352352 self .assertEqual (fi ._files , ('-' ,))
353353
354+ @support .ignore_warnings (category = DeprecationWarning )
354355 def test__getitem__ (self ):
355356 """Tests invoking FileInput.__getitem__() with the current
356357 line number"""
@@ -361,6 +362,14 @@ def test__getitem__(self):
361362 retval2 = fi [1 ]
362363 self .assertEqual (retval2 , "line2\n " )
363364
365+ def test__getitem___deprecation (self ):
366+ t = self .writeTmp ("line1\n line2\n " )
367+ with self .assertWarnsRegex (DeprecationWarning ,
368+ r'Use iterator protocol instead' ):
369+ with FileInput (files = [t ]) as fi :
370+ self .assertEqual (fi [0 ], "line1\n " )
371+
372+ @support .ignore_warnings (category = DeprecationWarning )
364373 def test__getitem__invalid_key (self ):
365374 """Tests invoking FileInput.__getitem__() with an index unequal to
366375 the line number"""
@@ -370,6 +379,7 @@ def test__getitem__invalid_key(self):
370379 fi [1 ]
371380 self .assertEqual (cm .exception .args , ("accessing lines out of order" ,))
372381
382+ @support .ignore_warnings (category = DeprecationWarning )
373383 def test__getitem__eof (self ):
374384 """Tests invoking FileInput.__getitem__() with the line number but at
375385 end-of-input"""
0 commit comments