2023-06-21 15:43:18 +00:00
|
|
|
import click
|
|
|
|
import pytest
|
|
|
|
import json
|
|
|
|
import os
|
2023-06-27 22:17:54 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv, set_key
|
|
|
|
|
|
|
|
load_dotenv()
|
2023-06-21 15:43:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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")
|
2023-06-27 22:17:54 +00:00
|
|
|
@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-21 15:43:18 +00:00
|
|
|
|
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 = {}
|
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",
|
|
|
|
default=os.path.join(Path.home(), "miniagi"),
|
2023-06-21 15:43:18 +00:00
|
|
|
)
|
|
|
|
|
2023-06-26 13:36:13 +00:00
|
|
|
with open(config_dir, "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-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)
|
2023-06-21 15:43:18 +00:00
|
|
|
|
2023-06-27 22:17:54 +00:00
|
|
|
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(
|
2023-06-27 22:17:54 +00:00
|
|
|
"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")
|
2023-06-21 15:43:18 +00:00
|
|
|
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
|
|
|
|
|
2023-06-27 22:17:54 +00:00
|
|
|
if mock:
|
|
|
|
pytest_args.append("--mock")
|
|
|
|
|
2023-06-22 12:18:22 +00:00
|
|
|
# Run pytest with the constructed arguments
|
|
|
|
pytest.main(pytest_args)
|
2023-06-21 15:43:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
start()
|