Skip to content

Commit d8d9e47

Browse files
committedMar 14, 2025·
Make sure unlink is always executed using try...finally - allow any error to propagate rather than catching (NO_JIRA)
1 parent 9c85798 commit d8d9e47

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed
 

‎main/githooks.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -461,24 +461,24 @@ class TestTrimTrailingWhitespace(unittest.TestCase):
461461
def test_trim_trailing_whitespace(self):
462462
content = 'first line\nsecond line \nthird line '
463463
trimmed_content = 'first line\nsecond line\nthird 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

Comments
 (0)
Please sign in to comment.