mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-22 16:34:25 +01:00
Fix debug code challenge (#4632)
This commit is contained in:
@@ -5,20 +5,27 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from autogpt.agent import Agent
|
||||
from autogpt.commands.execute_code import execute_python_file
|
||||
from autogpt.commands.file_operations import append_to_file, write_to_file
|
||||
from autogpt.config import Config
|
||||
from tests.challenges.challenge_decorator.challenge_decorator import challenge
|
||||
from tests.challenges.utils import run_interaction_loop
|
||||
from tests.challenges.utils import (
|
||||
copy_file_into_workspace,
|
||||
get_workspace_path,
|
||||
run_interaction_loop,
|
||||
)
|
||||
from tests.utils import requires_api_key
|
||||
|
||||
CYCLE_COUNT = 5
|
||||
EXPECTED_VALUES = ["[0, 1]", "[2, 5]", "[0, 3]"]
|
||||
DIRECTORY_PATH = Path(__file__).parent / "data"
|
||||
CODE_FILE_PATH = "code.py"
|
||||
TEST_FILE_PATH = "test.py"
|
||||
|
||||
|
||||
@pytest.mark.vcr
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
@challenge
|
||||
def test_debug_code_challenge_a(
|
||||
debug_code_agent: Agent,
|
||||
debug_code_agents: Agent,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
patched_api_requestor: MockerFixture,
|
||||
config: Config,
|
||||
@@ -33,17 +40,20 @@ def test_debug_code_challenge_a(
|
||||
:config: The config object for the agent.
|
||||
:level_to_run: The level to run.
|
||||
"""
|
||||
debug_code_agent = debug_code_agents[level_to_run - 1]
|
||||
|
||||
file_path = str(debug_code_agent.workspace.get_path("code.py"))
|
||||
|
||||
code_file_path = Path(__file__).parent / "data" / "two_sum.py"
|
||||
test_file_path = Path(__file__).parent / "data" / "two_sum_tests.py"
|
||||
|
||||
write_to_file(file_path, code_file_path.read_text(), config)
|
||||
copy_file_into_workspace(debug_code_agent, DIRECTORY_PATH, CODE_FILE_PATH)
|
||||
copy_file_into_workspace(debug_code_agent, DIRECTORY_PATH, TEST_FILE_PATH)
|
||||
|
||||
run_interaction_loop(monkeypatch, debug_code_agent, CYCLE_COUNT)
|
||||
|
||||
append_to_file(file_path, test_file_path.read_text(), config)
|
||||
output = execute_python_file(
|
||||
get_workspace_path(debug_code_agent, TEST_FILE_PATH), config
|
||||
)
|
||||
|
||||
output = execute_python_file(file_path, config)
|
||||
assert "error" not in output.lower(), f"Errors found in output: {output}!"
|
||||
|
||||
for expected_value in EXPECTED_VALUES:
|
||||
assert (
|
||||
expected_value in output
|
||||
), f"Expected output to contain {expected_value}, but it was not found in {output}!"
|
||||
|
||||
Reference in New Issue
Block a user