@@ -461,24 +461,24 @@ class TestTrimTrailingWhitespace(unittest.TestCase):
461461 def test_trim_trailing_whitespace (self ):
462462 content = 'first line\n second line \n third line '
463463 trimmed_content = 'first line\n second line\n third line'
464- name = NamedTemporaryFile ().name
465- Path (name ).write_text (content )
466- # Trailing whitespace found
467- retval = trim_trailing_whitespace_in_file (name , True , True )
468- self .assertEqual (retval , 1 )
469- self .assertEqual (Path (name ).read_text (), content )
470-
471- # Now remove the trailing whitespace
472- trim_trailing_whitespace_in_file (name , True , False , False )
473- # Trailing whitespace no longer found
474- self .assertEqual (Path (name ).read_text (), trimmed_content )
475- retval = trim_trailing_whitespace_in_file (name , True , True )
476- self .assertEqual (retval , 0 )
477-
464+
478465 try :
466+ name = NamedTemporaryFile ().name
467+ Path (name ).write_text (content )
468+ # Trailing whitespace found
469+ retval = trim_trailing_whitespace_in_file (name , True , True )
470+ self .assertEqual (retval , 1 )
471+ self .assertEqual (Path (name ).read_text (), content )
472+
473+ # Now remove the trailing whitespace
474+ trim_trailing_whitespace_in_file (name , True , False , False )
475+ # Trailing whitespace no longer found
476+ self .assertEqual (Path (name ).read_text (), trimmed_content )
477+ retval = trim_trailing_whitespace_in_file (name , True , True )
478+ self .assertEqual (retval , 0 )
479+ finally :
479480 Path (name ).unlink (name )
480- except Exception as e :
481- pass
481+
482482
483483 def test_decodeerror (self ):
484484 # A text file that is not utf-8 encoded - report and skip
0 commit comments