diff --git a/spec/python/test_debug_enum_name.py b/spec/python/test_debug_enum_name.py index 7e8430bc..f36af9e6 100644 --- a/spec/python/test_debug_enum_name.py +++ b/spec/python/test_debug_enum_name.py @@ -3,7 +3,9 @@ class TestDebugEnumName(unittest.TestCase): def test_debug_enum_name(self): - r = DebugEnumName.from_file("src/fixed_struct.bin") + with DebugEnumName.from_file('src/fixed_struct.bin') as r: + # --debug implies --no-auto-read + r._read() - # this test is meaningful only for languages that have --debug and do - # not save enum type info + # this test is meaningful only for languages that have --debug and do + # not save enum type info diff --git a/spec/python/test_opaque_external_type.py b/spec/python/test_opaque_external_type.py index 723839b1..a3365533 100644 --- a/spec/python/test_opaque_external_type.py +++ b/spec/python/test_opaque_external_type.py @@ -3,8 +3,7 @@ class TestOpaqueExternalType(unittest.TestCase): def test_opaque_external_type(self): - r = OpaqueExternalType.from_file("src/term_strz.bin") - - self.assertEqual(r.one.s1, "foo") - self.assertEqual(r.one.s2, "bar") - self.assertEqual(r.one.s3, "|baz@") + with OpaqueExternalType.from_file('src/term_strz.bin') as r: + self.assertEqual(r.one.s1, "foo") + self.assertEqual(r.one.s2, "bar") + self.assertEqual(r.one.s3, "|baz@") diff --git a/spec/python/test_opaque_with_param.py b/spec/python/test_opaque_with_param.py index 12c805d4..e7655e90 100644 --- a/spec/python/test_opaque_with_param.py +++ b/spec/python/test_opaque_with_param.py @@ -3,7 +3,6 @@ class TestOpaqueWithParam(unittest.TestCase): def test_opaque_with_param(self): - r = OpaqueWithParam.from_file("src/term_strz.bin") - - self.assertEqual(r.one.buf, "foo|b") - self.assertEqual(r.one.trailer, 0x61) + with OpaqueWithParam.from_file('src/term_strz.bin') as r: + self.assertEqual(r.one.buf, "foo|b") + self.assertEqual(r.one.trailer, 0x61) diff --git a/spec/python/test_params_def.py b/spec/python/test_params_def.py index eefa037f..5749bb9d 100644 --- a/spec/python/test_params_def.py +++ b/spec/python/test_params_def.py @@ -4,10 +4,7 @@ class TestParamsDef(unittest.TestCase): def test_params_def(self): - io = KaitaiStream(open("src/term_strz.bin", "rb")) - r = ParamsDef(5, True, io, None, None) - - self.assertEqual(r.buf, "foo|b") - self.assertEqual(r.trailer, 0x61) - - io.close() + io = KaitaiStream(open('src/term_strz.bin', 'rb')) + with ParamsDef(5, True, io, None, None) as r: + self.assertEqual(r.buf, "foo|b") + self.assertEqual(r.trailer, 0x61) diff --git a/spec/python/test_switch_cast.py b/spec/python/test_switch_cast.py index bdf5a0f1..eb3eb142 100644 --- a/spec/python/test_switch_cast.py +++ b/spec/python/test_switch_cast.py @@ -3,8 +3,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 diff --git a/spec/python/test_type_ternary_opaque.py b/spec/python/test_type_ternary_opaque.py index 403e332a..0fd3993e 100644 --- a/spec/python/test_type_ternary_opaque.py +++ b/spec/python/test_type_ternary_opaque.py @@ -3,8 +3,7 @@ class TestTypeTernaryOpaque(unittest.TestCase): def test_type_ternary_opaque(self): - r = TypeTernaryOpaque.from_file("src/term_strz.bin") - - self.assertEqual(r.dif.s1, "foo") - self.assertEqual(r.dif.s2, "bar") - self.assertEqual(r.dif.s3, "|baz@") + with TypeTernaryOpaque.from_file('src/term_strz.bin') as r: + self.assertEqual(r.dif.s1, "foo") + self.assertEqual(r.dif.s2, "bar") + self.assertEqual(r.dif.s3, "|baz@")