Skip to content

Commit

Permalink
deprecated 'validate' -> 'validate-circuit'
Browse files Browse the repository at this point in the history
  • Loading branch information
Joni Herttuainen committed Nov 17, 2023
1 parent 2d7147b commit de5cda6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ New Features
~~~~~~~~~~~~
- Added simulation config validation
- Added a new commandline subcommand: ``validate-simulation``
- Added an alias ``validate-circuit`` for the old ``validate`` subcommand

- deprecated ``validate``


Breaking Changes
~~~~~~~~~~~~~~~~
- Deprecated the commandline subcommand ``validate`` in favor of new ``validate-circuit`` command


Version v2.0.2
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This functionality is provided by either the cli function:

.. code-block:: shell
bluepysnap validate my/circuit/path/circuit_config.json
bluepysnap validate-circuit my/circuit/path/circuit_config.json
Or a python free function:
Expand Down
55 changes: 45 additions & 10 deletions bluepysnap/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""The project's command line launcher."""
import functools
import logging
import warnings

import click

from bluepysnap import circuit_validation, simulation_validation
from bluepysnap.utils import Deprecate

CLICK_EXISTING_FILE = click.Path(exists=True, file_okay=True, dir_okay=False)

Expand All @@ -20,18 +23,50 @@ def cli(verbose):
)


def circuit_validation_params(func):
"""Small helper to have shared params."""

@click.argument("config_file", type=CLICK_EXISTING_FILE)
@click.option(
"--skip-slow/--no-skip-slow",
default=True,
help=(
"Skip slow checks; checking all edges refer to existing node ids, "
"edge indices are correct, etc"
),
)
@click.option("--only-errors", is_flag=True, help="Only print fatal errors (ignore warnings)")
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


@cli.command()
@click.argument("config_file", type=CLICK_EXISTING_FILE)
@click.option(
"--skip-slow/--no-skip-slow",
default=True,
help=(
"Skip slow checks; checking all edges refer to existing node ids, "
"edge indices are correct, etc"
),
)
@click.option("--only-errors", is_flag=True, help="Only print fatal errors (ignore warnings)")
@circuit_validation_params
def validate(config_file, skip_slow, only_errors):
"""[DEPRECATED] Validate Sonata circuit based on config file.
Args:
config_file (str): path to Sonata circuit config file
skip_slow (bool): skip slow tests
only_errors (bool): only print fatal errors
"""
with warnings.catch_warnings():
# Making sure the warning is shown
warnings.simplefilter("always", DeprecationWarning)
Deprecate.warn(
"Calling circuit validation with 'validate' is deprecated. "
"Please use 'validate-circuit' instead."
)

circuit_validation.validate(config_file, skip_slow, only_errors)


@cli.command()
@circuit_validation_params
def validate_circuit(config_file, skip_slow, only_errors):
"""Validate Sonata circuit based on config file.
Args:
Expand Down
22 changes: 21 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import warnings
from unittest.mock import Mock, patch

import click
import pytest
from click.testing import CliRunner

from bluepysnap.cli import cli
from bluepysnap.exceptions import BluepySnapDeprecationWarning

from utils import TEST_DATA_DIR

Expand All @@ -13,7 +16,13 @@
@patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[]))
def test_cli_correct():
runner = CliRunner()
result = runner.invoke(cli, ["validate", str(TEST_DATA_DIR / "circuit_config.json")])

with pytest.warns(
BluepySnapDeprecationWarning,
match="Calling circuit validation with 'validate' is deprecated",
):
result = runner.invoke(cli, ["validate", str(TEST_DATA_DIR / "circuit_config.json")])

assert result.exit_code == 0
assert click.style("No Error: Success.", fg="green") in result.stdout

Expand All @@ -25,9 +34,20 @@ def test_cli_no_config():
assert "Missing argument 'CONFIG_FILE'" in result.stdout


@patch("bluepysnap.schemas.validate_nodes_schema", Mock(return_value=[]))
@patch("bluepysnap.schemas.validate_edges_schema", Mock(return_value=[]))
@patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[]))
def test_cli_validate_circuit_correct():
runner = CliRunner()
result = runner.invoke(cli, ["validate-circuit", str(TEST_DATA_DIR / "circuit_config.json")])
assert result.exit_code == 0
assert click.style("No Error: Success.", fg="green") 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
assert click.style("No Error: Success.", fg="green") in result.stdout

0 comments on commit de5cda6

Please sign in to comment.