@@ -3390,6 +3390,31 @@ def test_bytes_header_parser(self):
33903390 self .assertIsInstance (msg .get_payload (), str )
33913391 self .assertIsInstance (msg .get_payload (decode = True ), bytes )
33923392
3393+ def test_bytes_parser_does_not_close_file (self ):
3394+ with openfile ('msg_02.txt' , 'rb' ) as fp :
3395+ email .parser .BytesParser ().parse (fp )
3396+ self .assertFalse (fp .closed )
3397+
3398+ def test_bytes_parser_on_exception_does_not_close_file (self ):
3399+ with openfile ('msg_15.txt' , 'rb' ) as fp :
3400+ bytesParser = email .parser .BytesParser
3401+ self .assertRaises (email .errors .StartBoundaryNotFoundDefect ,
3402+ bytesParser (policy = email .policy .strict ).parse ,
3403+ fp )
3404+ self .assertFalse (fp .closed )
3405+
3406+ def test_parser_does_not_close_file (self ):
3407+ with openfile ('msg_02.txt' , 'r' ) as fp :
3408+ email .parser .Parser ().parse (fp )
3409+ self .assertFalse (fp .closed )
3410+
3411+ def test_parser_on_exception_does_not_close_file (self ):
3412+ with openfile ('msg_15.txt' , 'r' ) as fp :
3413+ parser = email .parser .Parser
3414+ self .assertRaises (email .errors .StartBoundaryNotFoundDefect ,
3415+ parser (policy = email .policy .strict ).parse , fp )
3416+ self .assertFalse (fp .closed )
3417+
33933418 def test_whitespace_continuation (self ):
33943419 eq = self .assertEqual
33953420 # This message contains a line after the Subject: header that has only
0 commit comments