diff --git a/snakebids/cli.py b/snakebids/cli.py index fe55a8ed..3aed8ef1 100644 --- a/snakebids/cli.py +++ b/snakebids/cli.py @@ -150,7 +150,7 @@ def create_parser(include_snakemake=False): "--skip-bids-validation", "--skip_bids-validation", action="store_true", - help=("Skip bids validation of input dataset") + help=("Skip bids validation of input dataset"), ) standard_group.add_argument( diff --git a/snakebids/core/input_generation.py b/snakebids/core/input_generation.py index ba6ee421..0185bf14 100644 --- a/snakebids/core/input_generation.py +++ b/snakebids/core/input_generation.py @@ -270,7 +270,7 @@ def generate_inputs( # Attempt to validate with node bids-validator, if needed validated = _validate_input_dir if not skip_bids_validation else None - + # Generates a BIDSLayout # If not skipping validation, set validate indicator to opposite of output # from _validate_input_dir, otherwise do not validate @@ -351,7 +351,7 @@ def _gen_bids_layout( derivatives subdirectory of the input dataset. validate : bool - A boolean that indicates whether validation should be performed on + A boolean that indicates whether validation should be performed on input dataset pybids_database_dir : str @@ -394,9 +394,9 @@ def _validate_input_dir( bids_dir: Union[Path, str], ) -> bool: """Perform validation of dataset. Initial attempt at validation performed - with node-version of bids-validator. If not found, will fall back to + with node-version of bids-validator. If not found, will fall back to validation integrated into pybids. - + Parameters ---------- bids_dir : str @@ -408,16 +408,14 @@ def _validate_input_dir( Indication of whether validation was successfully performed using the node-version of bids-validator """ - try: - validator_config_dict = { - "ignoredFiles": ['/participants.tsv'] - } + try: + validator_config_dict = {"ignoredFiles": ["/participants.tsv"]} with tempfile.NamedTemporaryFile(mode="w+", suffix=".json") as temp: temp.write(json.dumps(validator_config_dict)) temp.flush() - subprocess.check_call(['bids-validator', str(bids_dir), '-c', temp.name]) + subprocess.check_call(["bids-validator", str(bids_dir), "-c", temp.name]) return True except FileNotFoundError: diff --git a/snakebids/tests/data/dataset_description.json b/snakebids/tests/data/dataset_description.json new file mode 100644 index 00000000..4ee35cf3 --- /dev/null +++ b/snakebids/tests/data/dataset_description.json @@ -0,0 +1,4 @@ +{ + "Name": "Snakebids - test dataset", + "BIDSVersion": "1.8.0" +} \ No newline at end of file diff --git a/snakebids/tests/test_app.py b/snakebids/tests/test_app.py index c3b6d9e6..e4cd1d90 100644 --- a/snakebids/tests/test_app.py +++ b/snakebids/tests/test_app.py @@ -100,7 +100,7 @@ def test_runs_in_correct_mode( "pybids_db_reset": True, "snakefile": Path("Snakefile"), "output_dir": outputdir.resolve(), - "skip_bids_validation": False + "skip_bids_validation": False, } ) if root == "app" and tail == "": diff --git a/snakebids/tests/test_generate_inputs.py b/snakebids/tests/test_generate_inputs.py index 629debb5..d459c9bd 100644 --- a/snakebids/tests/test_generate_inputs.py +++ b/snakebids/tests/test_generate_inputs.py @@ -98,10 +98,7 @@ def test_ambiguous_paths_with_extra_entities_leads_to_error( with pytest.raises(ConfigError): generate_inputs( - root, - pybids_inputs, - skip_bids_validation=True, - use_bids_inputs=True + root, pybids_inputs, skip_bids_validation=True, use_bids_inputs=True ) @settings( @@ -129,10 +126,7 @@ def test_ambiguous_paths_with_missing_entity_leads_to_error( with pytest.raises(ConfigError): generate_inputs( - root, - pybids_inputs, - skip_bids_validation=True, - use_bids_inputs=True + root, pybids_inputs, skip_bids_validation=True, use_bids_inputs=True ) @settings( @@ -169,10 +163,7 @@ def test_entity_excluded_when_filter_false( ) data = generate_inputs( - root, - pybids_inputs, - skip_bids_validation=True, - use_bids_inputs=True + root, pybids_inputs, skip_bids_validation=True, use_bids_inputs=True ) assert data == expected @@ -252,10 +243,7 @@ def test_entity_excluded_when_filter_true(self, tmpdir: Path, dataset: BidsDatas ) data = generate_inputs( - root, - pybids_inputs, - skip_bids_validation=True, - use_bids_inputs=True + root, pybids_inputs, skip_bids_validation=True, use_bids_inputs=True ) assert data == expected @@ -1007,24 +995,36 @@ def start(self, tmpdir): # Copy test data shutil.copytree(self.bids_dir, f"{self.tmp_dir}/data") + assert filecmp.dircmp("snakebids/tests/data/bids_t1w", f"{self.tmp_dir}/data") + # Copy dataset description + shutil.copy( + "snakebids/tests/data/dataset_description.json", f"{self.tmp_dir}/data" + ) def test_check_validator(self): - """Test validator defaults to pybids""" - assert _validate_input_dir(self.bids_dir) == False - + """Test validator defaults to pybids (i.e. False)""" + assert _validate_input_dir(self.bids_dir) == False - # Test for validation failure def test_pybids_validation_fail(self): with pytest.raises(BIDSValidationError): _gen_bids_layout( - bids_dir=f"{self.tmp_dir}/data", + bids_dir=self.bids_dir, derivatives=False, pybids_database_dir=None, pybids_reset_database=False, validate=True, ) + def test_pybids_validation_pass(self): + assert _gen_bids_layout( + bids_dir=f"{self.tmp_dir}/data", + derivatives=False, + pybids_database_dir=None, + pybids_reset_database=False, + validate=True, + ) + class TestDB: @pytest.fixture(autouse=True)