From 45f2513a73f13011e5b27f00dfee805eaaff6a90 Mon Sep 17 00:00:00 2001 From: YOUNESS ZEMZGUI <31807902+younessZMZ@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:54:46 +0000 Subject: [PATCH] Adjust test_json_parser file (#1935) Co-authored-by: Reinier van der Leer --- .../{json_tests.py => _test_json_parser.py} | 0 tests/{ => unit}/test_json_parser.py | 57 +++---------------- 2 files changed, 9 insertions(+), 48 deletions(-) rename tests/unit/{json_tests.py => _test_json_parser.py} (100%) rename tests/{ => unit}/test_json_parser.py (60%) diff --git a/tests/unit/json_tests.py b/tests/unit/_test_json_parser.py similarity index 100% rename from tests/unit/json_tests.py rename to tests/unit/_test_json_parser.py diff --git a/tests/test_json_parser.py b/tests/unit/test_json_parser.py similarity index 60% rename from tests/test_json_parser.py rename to tests/unit/test_json_parser.py index 571ee5fa..69cddca6 100644 --- a/tests/test_json_parser.py +++ b/tests/unit/test_json_parser.py @@ -1,10 +1,10 @@ -import unittest +from unittest import TestCase -import tests.context from autogpt.json_utils.json_fix_llm import fix_and_parse_json +from tests.utils import skip_in_ci -class TestParseJson(unittest.TestCase): +class TestParseJson(TestCase): def test_valid_json(self): """Test that a valid JSON string is parsed correctly.""" json_str = '{"name": "John", "age": 30, "city": "New York"}' @@ -12,7 +12,7 @@ class TestParseJson(unittest.TestCase): self.assertEqual(obj, {"name": "John", "age": 30, "city": "New York"}) def test_invalid_json_minor(self): - """Test that an invalid JSON string can be fixed with gpt""" + """Test that an invalid JSON string can not be fixed without gpt""" json_str = '{"name": "John", "age": 30, "city": "New York",}' with self.assertRaises(Exception): fix_and_parse_json(json_str, try_to_fix_with_gpt=False) @@ -63,49 +63,10 @@ class TestParseJson(unittest.TestCase): "speak": "I will start browsing the repository to find any issues we can fix.", }, } - # Assert that this raises an exception: - self.assertEqual( - fix_and_parse_json(json_str, try_to_fix_with_gpt=False), good_obj - ) - def test_invalid_json_leading_sentence_with_gpt(self): - """Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False""" - json_str = """I will first need to browse the repository (https://github.com/Torantulino/Auto-GPT) and identify any potential bugs that need fixing. I will use the "browse_website" command for this. + # # Assert that this can be fixed with GPT + # self.assertEqual(fix_and_parse_json(json_str), good_obj) -{ - "command": { - "name": "browse_website", - "args":{ - "url": "https://github.com/Torantulino/Auto-GPT" - } - }, - "thoughts": - { - "text": "Browsing the repository to identify potential bugs", - "reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.", - "plan": "- Analyze the repository for potential bugs and areas of improvement", - "criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.", - "speak": "I am browsing the repository to identify potential bugs." - } -}""" - good_obj = { - "command": { - "name": "browse_website", - "args": {"url": "https://github.com/Torantulino/Auto-GPT"}, - }, - "thoughts": { - "text": "Browsing the repository to identify potential bugs", - "reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.", - "plan": "- Analyze the repository for potential bugs and areas of improvement", - "criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.", - "speak": "I am browsing the repository to identify potential bugs.", - }, - } - # Assert that this raises an exception: - self.assertEqual( - fix_and_parse_json(json_str, try_to_fix_with_gpt=False), good_obj - ) - - -if __name__ == "__main__": - unittest.main() + # Assert that trying to fix this without GPT raises an exception + with self.assertRaises(Exception): + fix_and_parse_json(json_str, try_to_fix_with_gpt=False)