2023-06-21 15:43:18 +00:00
|
|
|
import json
|
|
|
|
import os
|
2023-07-02 20:14:49 +00:00
|
|
|
import sys
|
2023-06-27 22:17:54 +00:00
|
|
|
from pathlib import Path
|
2023-07-09 01:43:38 +00:00
|
|
|
from typing import Any
|
2023-07-02 20:14:49 +00:00
|
|
|
|
|
|
|
import click
|
|
|
|
import pytest
|
2023-07-09 01:43:38 +00:00
|
|
|
from dotenv import load_dotenv
|
2023-06-27 22:17:54 +00:00
|
|
|
|
|
|
|
load_dotenv()
|
2023-06-21 15:43:18 +00:00
|
|
|
|
2023-07-02 14:38:30 +00:00
|
|
|
CURRENT_DIRECTORY = Path(__file__).resolve().parent
|
|
|
|
|
|
|
|
|
2023-07-03 18:53:28 +00:00
|
|
|
CONFIG_PATH = str(Path(os.getcwd()) / "config.json")
|
2023-07-02 14:38:30 +00:00
|
|
|
|
|
|
|
REGRESSION_TESTS_PATH = str(Path(os.getcwd()) / "regression_tests.json")
|
2023-06-21 15:43:18 +00:00
|
|
|
|
2023-07-02 20:14:49 +00:00
|
|
|
|
2023-06-21 15:43:18 +00:00
|
|
|
@click.group()
|
2023-07-02 20:14:49 +00:00
|
|
|
def cli() -> None:
|
2023-06-21 15:43:18 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
2023-06-22 12:18:22 +00:00
|
|
|
@click.option("--category", default=None, help="Specific category to run")
|
2023-07-06 04:03:45 +00:00
|
|
|
@click.option("--maintain", is_flag=True, help="Runs only regression tests")
|
2023-07-09 01:43:38 +00:00
|
|
|
@click.option("--improve", is_flag=True, help="Run only non-regression tests")
|
2023-06-27 22:17:54 +00:00
|
|
|
@click.option("--mock", is_flag=True, help="Run with mock")
|
2023-07-09 01:43:38 +00:00
|
|
|
def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:
|
2023-06-22 12:18:22 +00:00
|
|
|
"""Start the benchmark tests. If a category flag is provided, run the categories with that mark."""
|
|
|
|
# Check if configuration file exists and is not empty
|
2023-07-09 01:43:38 +00:00
|
|
|
if maintain and improve:
|
|
|
|
print(
|
|
|
|
"Error: You can't use both --maintain and --improve at the same time. Please choose one."
|
|
|
|
)
|
|
|
|
return 1
|
|
|
|
|
2023-07-02 14:38:30 +00:00
|
|
|
if not os.path.exists(CONFIG_PATH) or os.stat(CONFIG_PATH).st_size == 0:
|
2023-06-22 12:18:22 +00:00
|
|
|
config = {}
|
2023-06-21 15:43:18 +00:00
|
|
|
|
|
|
|
config["workspace"] = click.prompt(
|
2023-06-27 22:17:54 +00:00
|
|
|
"Please enter a new workspace path",
|
2023-06-30 15:55:43 +00:00
|
|
|
default=os.path.join(Path.home(), "workspace"),
|
|
|
|
)
|
|
|
|
|
2023-07-04 17:23:00 +00:00
|
|
|
config["entry_path"] = click.prompt(
|
2023-06-30 15:55:43 +00:00
|
|
|
"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-21 15:43:18 +00:00
|
|
|
)
|
|
|
|
|
2023-07-02 14:38:30 +00:00
|
|
|
with open(CONFIG_PATH, "w") as f:
|
2023-06-21 15:43:18 +00:00
|
|
|
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-07-02 14:38:30 +00:00
|
|
|
with open(CONFIG_PATH, "r") as f:
|
2023-06-22 12:18:22 +00:00
|
|
|
config = json.load(f)
|
2023-06-21 15:43:18 +00:00
|
|
|
|
2023-07-09 01:43:38 +00:00
|
|
|
os.environ["MOCK_TEST"] = "True" if mock else "False"
|
2023-06-27 22:17:54 +00:00
|
|
|
|
2023-07-02 14:38:30 +00:00
|
|
|
if not os.path.exists(REGRESSION_TESTS_PATH):
|
|
|
|
with open(REGRESSION_TESTS_PATH, "a"):
|
2023-06-27 17:25:47 +00:00
|
|
|
pass
|
|
|
|
|
2023-06-22 12:18:22 +00:00
|
|
|
print("Current configuration:")
|
|
|
|
for key, value in config.items():
|
|
|
|
print(f"{key}: {value}")
|
|
|
|
|
2023-07-02 14:38:30 +00:00
|
|
|
pytest_args = ["-vs"]
|
2023-06-22 12:18:22 +00:00
|
|
|
if category:
|
2023-07-02 20:14:49 +00:00
|
|
|
pytest_args.extend(["-m", category])
|
2023-07-09 01:43:38 +00:00
|
|
|
print("Starting benchmark tests ", category)
|
2023-06-21 15:43:18 +00:00
|
|
|
else:
|
2023-07-09 01:43:38 +00:00
|
|
|
print("Running all categories")
|
|
|
|
|
|
|
|
if maintain:
|
|
|
|
print("Running only regression tests")
|
|
|
|
pytest_args.append("--maintain")
|
|
|
|
elif improve:
|
|
|
|
print("Running only non-regression tests")
|
|
|
|
pytest_args.append("--improve")
|
2023-06-22 12:18:22 +00:00
|
|
|
|
2023-06-27 22:17:54 +00:00
|
|
|
if mock:
|
|
|
|
pytest_args.append("--mock")
|
|
|
|
|
2023-07-09 20:31:31 +00:00
|
|
|
# when used as a library, the pytest directory to execute is in the CURRENT_DIRECTORY
|
|
|
|
pytest_args.append(str(CURRENT_DIRECTORY))
|
|
|
|
|
2023-07-02 20:14:49 +00:00
|
|
|
return sys.exit(pytest.main(pytest_args))
|
2023-06-21 15:43:18 +00:00
|
|
|
|
2023-07-02 20:14:49 +00:00
|
|
|
|
2023-07-09 01:43:38 +00:00
|
|
|
def get_regression_data() -> Any:
|
2023-07-02 20:14:49 +00:00
|
|
|
with open(REGRESSION_TESTS_PATH, "r") as file:
|
2023-07-02 14:38:30 +00:00
|
|
|
data = json.load(file)
|
|
|
|
|
2023-07-09 01:43:38 +00:00
|
|
|
return data
|
2023-07-02 14:38:30 +00:00
|
|
|
|
2023-07-02 20:14:49 +00:00
|
|
|
|
2023-06-21 15:43:18 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
start()
|