From 0c7b7e5de8f99fb9254d54b327a4cfccb9b3ae57 Mon Sep 17 00:00:00 2001 From: digger-yu Date: Thu, 13 Apr 2023 18:43:32 +0800 Subject: [PATCH] Update test_json_parser.py Optimize part of the code to maintain uniformity --- tests/test_json_parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_json_parser.py b/tests/test_json_parser.py index b8cb2680..352cf3d4 100644 --- a/tests/test_json_parser.py +++ b/tests/test_json_parser.py @@ -13,12 +13,14 @@ class TestParseJson(unittest.TestCase): def test_invalid_json_minor(self): # Test that an invalid JSON string can be fixed with gpt json_str = '{"name": "John", "age": 30, "city": "New York",}' - self.assertRaises(Exception, fix_and_parse_json, json_str, try_to_fix_with_gpt=False) + with self.assertRaises(Exception): + fix_and_parse_json(json_str, try_to_fix_with_gpt=False) def test_invalid_json_major_with_gpt(self): # Test that an invalid JSON string raises an error when try_to_fix_with_gpt is False json_str = 'BEGIN: "name": "John" - "age": 30 - "city": "New York" :END' - self.assertRaises(Exception, fix_and_parse_json, json_str, try_to_fix_with_gpt=False) + with self.assertRaises(Exception): + fix_and_parse_json(json_str, try_to_fix_with_gpt=False) def test_invalid_json_major_without_gpt(self): # Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False