Dynamic workspace path (#56)

This commit is contained in:
Silen Naihin
2023-07-04 22:06:49 -04:00
committed by GitHub
parent 351131bbff
commit bfc7dfdb29
3 changed files with 24 additions and 3 deletions

View File

@@ -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

View File

@@ -26,4 +26,4 @@
"dependencies": [],
"test": "agbenchmark/challenges/retrieval/r3/r3_test.py"
}
}
}