From 715a7156f25586e6dfe152bfaa22dfe0173054af Mon Sep 17 00:00:00 2001 From: Joni Herttuainen Date: Fri, 17 Nov 2023 13:25:21 +0100 Subject: [PATCH] Add simulation validation as click command --- bluepysnap/cli.py | 19 ++++++++++++++++--- tests/test_cli.py | 8 ++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bluepysnap/cli.py b/bluepysnap/cli.py index a5dba9ff..c952071f 100644 --- a/bluepysnap/cli.py +++ b/bluepysnap/cli.py @@ -3,7 +3,9 @@ import click -from bluepysnap import circuit_validation +from bluepysnap import circuit_validation, simulation_validation + +CLICK_EXISTING_FILE = click.Path(exists=True, file_okay=True, dir_okay=False) @click.group() @@ -19,7 +21,7 @@ def cli(verbose): @cli.command() -@click.argument("config_file", type=click.Path(exists=True, file_okay=True, dir_okay=False)) +@click.argument("config_file", type=CLICK_EXISTING_FILE) @click.option( "--skip-slow/--no-skip-slow", default=True, @@ -30,7 +32,7 @@ def cli(verbose): ) @click.option("--only-errors", is_flag=True, help="Only print fatal errors (ignore warnings)") def validate(config_file, skip_slow, only_errors): - """Validate of Sonata circuit based on config file. + """Validate Sonata circuit based on config file. Args: config_file (str): path to Sonata circuit config file @@ -38,3 +40,14 @@ def validate(config_file, skip_slow, only_errors): only_errors (bool): only print fatal errors """ circuit_validation.validate(config_file, skip_slow, only_errors) + + +@cli.command() +@click.argument("config_file", type=CLICK_EXISTING_FILE) +def validate_simulation(config_file): + """Validate Sonata simulation based on config file. + + Args: + config_file (str): path to Sonata simulation config file + """ + simulation_validation.validate(config_file) diff --git a/tests/test_cli.py b/tests/test_cli.py index a70f112b..c36d92d1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -23,3 +23,11 @@ def test_cli_no_config(): result = runner.invoke(cli, ["validate"]) assert result.exit_code == 2 assert "Missing argument 'CONFIG_FILE'" in result.stdout + + +def test_cli_validate_simulation_correct(): + runner = CliRunner() + result = runner.invoke( + cli, ["validate-simulation", str(TEST_DATA_DIR / "simulation_config.json")] + ) + assert result.exit_code == 0