From 47fe558ef5a1b1c1df14e074a8a82c2811a89dc7 Mon Sep 17 00:00:00 2001 From: Mingun Date: Mon, 15 Apr 2024 21:28:42 +0500 Subject: [PATCH] Python: fix ResourceWarning: unclosed file <_io.FileIO name='...' mode='rb' closefd=True> where ... = src/fixed_struct.bin = src/switch_opcodes.bin --- spec/python/test_debug_enum_name.py | 7 +++---- spec/python/test_switch_cast.py | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/python/test_debug_enum_name.py b/spec/python/test_debug_enum_name.py index 2421f2953..dcb166f2d 100644 --- a/spec/python/test_debug_enum_name.py +++ b/spec/python/test_debug_enum_name.py @@ -4,7 +4,6 @@ class TestDebugEnumName(unittest.TestCase): def test_debug_enum_name(self): - r = DebugEnumName.from_file("src/fixed_struct.bin") - - # this test is meaningful only for languages that have --debug and do - # not save enum type info + with DebugEnumName.from_file("src/fixed_struct.bin") as R: + # this test is meaningful only for languages that have --debug and do + # not save enum type info diff --git a/spec/python/test_switch_cast.py b/spec/python/test_switch_cast.py index 8f9b3f3cf..a0a8f9268 100644 --- a/spec/python/test_switch_cast.py +++ b/spec/python/test_switch_cast.py @@ -4,8 +4,7 @@ class TestSwitchCast(unittest.TestCase): def test_switch_cast(self): - r = SwitchCast.from_file("src/switch_opcodes.bin") - - self.assertEqual(r.first_obj.value, "foobar") - self.assertEqual(r.second_val, 0x42) - # unable to test "err_cast" here + with SwitchCast.from_file('src/switch_opcodes.bin') as r: + self.assertEqual(r.first_obj.value, "foobar") + self.assertEqual(r.second_val, 0x42) + # unable to test "err_cast" here