AutoGPT/agbenchmark/start_benchmark.py

101 lines
3.1 KiB
Python
Raw Normal View History

import click
import pytest
import json
import os
from pathlib import Path
from dotenv import load_dotenv, set_key
load_dotenv()
@click.group()
def cli():
pass
@cli.command()
2023-06-22 12:18:22 +00:00
@click.option("--category", default=None, help="Specific category to run")
@click.option("--noreg", is_flag=True, help="Skip regression tests")
@click.option("--mock", is_flag=True, help="Run with mock")
def start(category, noreg, mock):
2023-06-22 12:18:22 +00:00
"""Start the benchmark tests. If a category flag is provided, run the categories with that mark."""
config_file = "agbenchmark/config.json"
2023-06-26 13:36:13 +00:00
config_dir = os.path.abspath(config_file)
2023-06-22 12:18:22 +00:00
# Check if configuration file exists and is not empty
2023-06-26 13:36:13 +00:00
if not os.path.exists(config_dir) or os.stat(config_dir).st_size == 0:
2023-06-22 12:18:22 +00:00
config = {}
config["workspace"] = click.prompt(
"Please enter a new workspace path",
default=os.path.join(Path.home(), "workspace"),
)
config["func_path"] = click.prompt(
"Please enter a the path to your run_specific_agent function implementation",
default="/benchmarks.py",
)
config["cutoff"] = click.prompt(
"Please enter a hard cutoff runtime for your agent",
default="60",
)
2023-06-26 13:36:13 +00:00
with open(config_dir, "w") as f:
json.dump(config, f)
2023-06-22 12:18:22 +00:00
else:
# If the configuration file exists and is not empty, load it
2023-06-26 13:36:13 +00:00
with open(config_dir, "r") as f:
2023-06-22 12:18:22 +00:00
config = json.load(f)
set_key(".env", "MOCK_TEST", "True" if mock else "False")
if mock:
config["workspace"] = "agbenchmark/mocks/workspace"
2023-06-26 13:36:13 +00:00
# create workspace directory if it doesn't exist
2023-06-27 17:25:47 +00:00
workspace_path = os.path.abspath(config["workspace"])
2023-06-26 13:36:13 +00:00
if not os.path.exists(workspace_path):
os.makedirs(workspace_path, exist_ok=True)
2023-06-27 17:25:47 +00:00
regression_path = os.path.abspath(
"agbenchmark/tests/regression/regression_tests.json"
2023-06-27 17:25:47 +00:00
)
if not os.path.exists(regression_path):
with open(regression_path, "a"):
pass
2023-06-22 12:18:22 +00:00
print("Current configuration:")
for key, value in config.items():
print(f"{key}: {value}")
print("Starting benchmark tests...", category)
pytest_args = ["agbenchmark", "-vs"]
if category:
pytest_args.extend(
["-m", category]
) # run categorys that are of a specific marker
if noreg:
pytest_args.extend(
["-k", "not regression"]
) # run categorys that are of a specific marker but don't include regression categorys
print(f"Running {'non-regression' + category if noreg else category} categorys")
else:
2023-06-22 12:18:22 +00:00
if noreg:
print("Running all non-regression categorys")
pytest_args.extend(
["-k", "not regression"]
) # run categorys that are not regression categorys
else:
print("Running all categorys") # run all categorys
if mock:
pytest_args.append("--mock")
2023-06-22 12:18:22 +00:00
# Run pytest with the constructed arguments
pytest.main(pytest_args)
if __name__ == "__main__":
start()