Skip to content

Commit

Permalink
Add option to only print/return fatal errors in validation (#166)
Browse files Browse the repository at this point in the history
Co-authored-by: Gianluca Ficarelli <26835404+GianlucaFicarelli@users.noreply.github.com>
  • Loading branch information
joni-herttuainen and GianlucaFicarelli committed Sep 2, 2022
1 parent b3342d0 commit 62d2e80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
9 changes: 7 additions & 2 deletions bluepysnap/circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,14 @@ def validate_networks(config, skip_slow):
return errors


def validate(config_file, skip_slow, print_errors=True):
def validate(config_file, skip_slow, only_errors=False, print_errors=True):
"""Validates Sonata circuit.
Args:
config_file (str): path to Sonata circuit config file official checks.
skip_slow(bool): skip slow tests
skip_slow (bool): skip slow tests
only_errors (bool): only return/print fatal errors
print_errors (bool): print errors
Returns:
list: List of errors, empty if no errors
Expand All @@ -606,6 +608,9 @@ def validate(config_file, skip_slow, print_errors=True):
if "networks" in config:
errors += validate_networks(config, skip_slow)

if only_errors:
errors = [e for e in errors if e.level == Error.FATAL]

if print_errors:
_print_errors(errors)

Expand Down
8 changes: 5 additions & 3 deletions bluepysnap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def cli(verbose):
"edge indices are correct, etc"
),
)
def validate(config_file, skip_slow):
@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.
Args:
config_file (str): path to Sonata circuit config file
skip_slow(bool): skip slow tests
skip_slow (bool): skip slow tests
only_errors (bool): only print fatal errors
"""
circuit_validation.validate(config_file, skip_slow)
circuit_validation.validate(config_file, skip_slow, only_errors)
17 changes: 17 additions & 0 deletions tests/test_circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ def test_skip_slow():
patched.assert_not_called()


def test_only_errors():
with patch(f"{test_module.__name__}.validate_networks") as patched:
patched.return_value = [
Error(Error.FATAL, "fatal_error"),
Error(Error.WARNING, "a mere warning"),
Error(Error.INFO, "utterly useful message"),
]

errors = test_module.validate(
str(TEST_DATA_DIR / "circuit_config.json"),
skip_slow=True,
only_errors=True,
)
assert len(errors) == 1
assert list(errors)[0] == Error(Error.FATAL, "fatal_error")


def test_print_errors(capsys):
with copy_test_data() as (_, config_copy_path):
with edit_config(config_copy_path) as config:
Expand Down

0 comments on commit 62d2e80

Please sign in to comment.