AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Enhanced Test Report Directory Naming and Handling (#312)
Swifty16053a313726
diff --git a/agbenchmark/utils/utils.py b/agbenchmark/utils/utils.pyindex f9bff83d13..12b58beb4f 100644--- a/agbenchmark/utils/utils.py+++ b/agbenchmark/utils/utils.py@@ -1,9 +1,8 @@# radio charts, logs, helper functions for tests, anything else relevant.-import mathimport osimport reimport sys-from datetime import datetime+from datetime import datetime, timezonefrom pathlib import Pathfrom typing import Any, List, Optional@@ -18,76 +17,45 @@ AGENT_NAME = os.getenv("AGENT_NAME")REPORT_LOCATION = os.getenv("REPORT_LOCATION", None)-def calculate_info_test_path(reports_path: Path) -> str:- command = sys.argv-- if not reports_path.exists():- reports_path.mkdir(parents=True, exist_ok=True)-- # Collect all directories in reports_path- all_items = os.listdir(str(reports_path))- dirs = [item for item in all_items if os.path.isdir(reports_path / item)]-- # Default naming scheme- dir_count = len(dirs)- run_name = f"folder{dir_count + 1}_{datetime.now().strftime('%m-%d-%H-%M')}"-- test_index = None- test_arg = None- # Check command-line arguments- if "--test" in command:- test_index = command.index("--test")- elif "--suite" in command:- test_index = command.index("--suite")- elif "--category" in command:- test_index = command.index("--category")- elif "--maintain" in command:- test_index = command.index("--maintain")- test_arg = "maintain"- elif "--improve" in command:- test_index = command.index("--improve")- test_arg = "improve"- elif "--improve" in command:- test_index = command.index("--explore")- test_arg = "explore"-- if test_index:- if not test_arg:- test_arg = command[test_index + 1]-- # collect related directories and their prefix numbers- related_dirs = []- prefix_numbers = []-- for dir in dirs:- dir_parts = dir.split("_")- try:- prefix = float(dir_parts[0][6:])- test_name = "_".join(dir_parts[1:])- if test_arg == test_name:- prefix_numbers.append(math.floor(prefix))- related_dirs.append(test_name)- except:- pass-- related_dir_count = len(related_dirs)-- if related_dir_count == 0:- max_prefix = max(prefix_numbers, default=0)- run_name = f"folder{max_prefix + 1}_{test_arg}"- else:- print(- f"Found {related_dir_count} directories with '{test_arg}' in the name"- )- prefix = max(prefix_numbers)- run_name = f"folder{prefix}.{related_dir_count}_{test_arg}"-- new_dir_path = reports_path / run_name-- if not os.path.exists(new_dir_path):- os.makedirs(new_dir_path)-- return str(new_dir_path)+def calculate_info_test_path(base_path: Path) -> str:+ """+ Calculates the path to the directory where the test report will be saved.+ """+ # Ensure the reports path exists+ base_path.mkdir(parents=True, exist_ok=True)++ # Get current UTC date-time stamp+ date_stamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")++ # Default run name+ run_name = "full_run"++ # Map command-line arguments to their respective labels+ arg_labels = {+ "--test": None,+ "--suite": None,+ "--category": None,+ "--maintain": "maintain",+ "--improve": "improve",+ "--explore": "explore",+ }++ # Identify the relevant command-line argument+ for arg, label in arg_labels.items():+ if arg in sys.argv:+ test_arg = sys.argv[sys.argv.index(arg) + 1] if label is None else None+ run_name = arg.strip("--")+ if test_arg:+ run_name = f"{run_name}_{test_arg}"+ break++ # Create the full new directory path with ISO standard UTC date-time stamp+ report_path = base_path / f"{date_stamp}_{run_name}"++ # Ensure the new directory is created+ report_path.mkdir(exist_ok=True)++ return str(report_path)def replace_backslash(value: Any) -> Any: