Skip to content

Commit

Permalink
make catching InvalidBidsError configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitj committed May 19, 2023
1 parent 65cfd1b commit 618b763
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions snakebids/plugins/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class BidsValidator:
Snakebids application to be run
"""

def __init__(self) -> None:
pass
def __init__(self, raise_invalid_bids: bool = True) -> None:
self.raise_invalid_bids = raise_invalid_bids

def __call__(self, app: SnakeBidsApp) -> None:
# Skip bids validation
Expand Down Expand Up @@ -54,4 +54,5 @@ def __call__(self, app: SnakeBidsApp) -> None:
# Any other bids-validator error
except subprocess.CalledProcessError as err:
app.config["plugins.validator.success"] = False
raise InvalidBidsError from err
if self.raise_invalid_bids:
raise InvalidBidsError from err
18 changes: 17 additions & 1 deletion snakebids/tests/test_validate_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_missing_bids_validator(
assert caplog.records[0].levelname == "WARNING"
assert "Missing bids-validator installation" in caplog.records[0].message

def test_validation_error(self, app: SnakeBidsApp, mocker: MockerFixture):
def test_raise_validation_error(self, app: SnakeBidsApp, mocker: MockerFixture):
# Test for any other bids-validation error
mocker.patch(
"subprocess.check_call", side_effect=subprocess.CalledProcessError(1, "")
Expand All @@ -78,3 +78,19 @@ def test_validation_error(self, app: SnakeBidsApp, mocker: MockerFixture):

# Check validation failure
assert not app.config["plugins.validator.success"]

def test_ignore_validation_error(self, app: SnakeBidsApp, mocker: MockerFixture):
# Test for any other bids-validation error
mocker.patch(
"subprocess.check_call", side_effect=subprocess.CalledProcessError(1, "")
)

app.config["bids_dirs"] = "path/to/bids/dir"
app.config["plugins.validator.skip"] = False

# Check if error is skipped on invalid
validator = BidsValidator(raise_invalid_bids=False)
validator(app)

# Check validation failure
assert not app.config["plugins.validator.success"]

0 comments on commit 618b763

Please sign in to comment.