From bfc7dfdb291099d75dcc1e0dbe3e03439b5163f5 Mon Sep 17 00:00:00 2001 From: Silen Naihin Date: Tue, 4 Jul 2023 22:06:49 -0400 Subject: [PATCH] Dynamic workspace path (#56) --- agbenchmark/conftest.py | 23 ++++++++++++++++++++++- agent/mini-agi | 2 +- regression_tests.json | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/agbenchmark/conftest.py b/agbenchmark/conftest.py index 613565fd..66ede2c0 100644 --- a/agbenchmark/conftest.py +++ b/agbenchmark/conftest.py @@ -1,6 +1,7 @@ import json import os import shutil +from pathlib import Path # noqa from typing import Any, Dict, Generator, List import pytest @@ -9,6 +10,21 @@ from agbenchmark.start_benchmark import CONFIG_PATH, REGRESSION_TESTS_PATH from agbenchmark.tests.regression.RegressionManager import RegressionManager +def get_dynamic_workspace(config: Dict[str, Any]) -> str: + # Extract the string inside ${...} + path_expr = config["workspace"][2:-1] + + # Check if it starts with "os.path.join" + if path_expr.strip().startswith("os.path.join"): + # Evaluate the path string + path_value = eval(path_expr) + + # Replace the original string with the evaluated result + return path_value + else: + raise ValueError("Invalid workspace path expression.") + + @pytest.fixture(scope="module") def config(request: Any) -> None: print(f"Config file: {CONFIG_PATH}") @@ -17,11 +33,16 @@ def config(request: Any) -> None: if request.config.getoption("--mock"): config["workspace"] = "agbenchmark/mocks/workspace" + elif config.get("workspace", "").startswith("${") and config.get( + "workspace", "" + ).endswith("}"): + path = get_dynamic_workspace(config) + config["workspace"] = path return config -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", autouse=True) def workspace(config: Dict[str, Any]) -> Generator[str, None, None]: yield config["workspace"] # teardown after test function completes diff --git a/agent/mini-agi b/agent/mini-agi index d99220c0..4af8a7e6 160000 --- a/agent/mini-agi +++ b/agent/mini-agi @@ -1 +1 @@ -Subproject commit d99220c058c9fb45f83256ea361b55dba506fa75 +Subproject commit 4af8a7e6085f0518f06180fbf87024a2c9db4c88 diff --git a/regression_tests.json b/regression_tests.json index 853c38dc..d0a8ed19 100644 --- a/regression_tests.json +++ b/regression_tests.json @@ -26,4 +26,4 @@ "dependencies": [], "test": "agbenchmark/challenges/retrieval/r3/r3_test.py" } -} \ No newline at end of file +}