Skip to content

Commit 1736b51

Browse files
committed
add unit test for cubids bids-version
1 parent 75bf86e commit 1736b51

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed

cubids/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _parse_validate():
4343
type=PathExists,
4444
action="store",
4545
help=(
46-
"the root of a BIDS dataset. It should contain "
46+
"The root of a BIDS dataset. It should contain "
4747
"sub-X directories and dataset_description.json"
4848
),
4949
)
@@ -119,7 +119,7 @@ def _parse_bids_version():
119119
type=PathExists,
120120
action="store",
121121
help=(
122-
"the root of a BIDS dataset. It should contain "
122+
"The root of a BIDS dataset. It should contain "
123123
"sub-X directories and dataset_description.json"
124124
),
125125
)
@@ -188,7 +188,7 @@ def _parse_group():
188188
type=PathExists,
189189
action="store",
190190
help=(
191-
"the root of a BIDS dataset. It should contain "
191+
"The root of a BIDS dataset. It should contain "
192192
"sub-X directories and dataset_description.json"
193193
),
194194
)
@@ -255,7 +255,7 @@ def _parse_apply():
255255
type=PathExists,
256256
action="store",
257257
help=(
258-
"the root of a BIDS dataset. It should contain "
258+
"The root of a BIDS dataset. It should contain "
259259
"sub-X directories and dataset_description.json"
260260
),
261261
)
@@ -351,7 +351,7 @@ def _parse_datalad_save():
351351
type=PathExists,
352352
action="store",
353353
help=(
354-
"the root of a BIDS dataset. It should contain "
354+
"The root of a BIDS dataset. It should contain "
355355
"sub-X directories and dataset_description.json"
356356
),
357357
)
@@ -393,7 +393,7 @@ def _parse_undo():
393393
type=PathExists,
394394
action="store",
395395
help=(
396-
"the root of a BIDS dataset. It should contain "
396+
"The root of a BIDS dataset. It should contain "
397397
"sub-X directories and dataset_description.json"
398398
),
399399
)
@@ -617,7 +617,7 @@ def _parse_remove_metadata_fields():
617617
type=PathExists,
618618
action="store",
619619
help=(
620-
"the root of a BIDS dataset. It should contain "
620+
"The root of a BIDS dataset. It should contain "
621621
"sub-X directories and dataset_description.json"
622622
),
623623
)
@@ -663,7 +663,7 @@ def _parse_print_metadata_fields():
663663
type=PathExists,
664664
action="store",
665665
help=(
666-
"the root of a BIDS dataset. It should contain "
666+
"The root of a BIDS dataset. It should contain "
667667
"sub-X directories and dataset_description.json"
668668
),
669669
)

cubids/cubids.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,10 @@ def get_all_metadata_fields(self):
13461346
metadata = json.loads(content)
13471347
found_fields.update(metadata.keys())
13481348
except json.JSONDecodeError as e:
1349-
print(f"Error decoding JSON in {json_file}: {e}")
1349+
warnings.warn(f"Error decoding JSON in {json_file}: {e}")
13501350
except Exception as e:
1351-
print(f"Unexpected error with file {json_file}: {e}")
1351+
warnings.warn(f"Unexpected error with file {json_file}: {e}")
1352+
13521353
return sorted(found_fields)
13531354

13541355
def remove_metadata_fields(self, fields_to_remove):

cubids/tests/test_bond.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy as np
1010
import pandas as pd
1111
import pytest
12+
from packaging.version import Version
1213

1314
from cubids.cubids import CuBIDS
1415
from cubids.metadata_merge import merge_json_into_json, merge_without_overwrite
@@ -22,7 +23,15 @@
2223
file_hash,
2324
get_data,
2425
)
25-
from cubids.validator import build_validator_call, parse_validator_output, run_validator
26+
from cubids.validator import (
27+
build_validator_call,
28+
parse_validator_output,
29+
run_validator,
30+
get_bids_validator_version,
31+
extract_summary_info,
32+
update_dataset_description,
33+
bids_validator_version,
34+
)
2635

2736
COMPLETE_KEY_GROUPS = [
2837
"acquisition-HASC55AP_datatype-dwi_suffix-dwi",
@@ -1028,6 +1037,47 @@ def test_validator(tmp_path):
10281037
assert isinstance(parsed, pd.DataFrame)
10291038

10301039

1040+
def bids_validator_version(tmp_path):
1041+
"""Test validator.bids_validator_version."""
1042+
# Get the BIDS validator version
1043+
validator_version = get_bids_validator_version()
1044+
# Extract schemaVersion
1045+
summary_info = extract_summary_info(decoded)
1046+
1047+
1048+
def test_bids_version(tmp_path):
1049+
"""Test workflows.bids_version."""
1050+
data_root = get_data(tmp_path)
1051+
bids_dir = Path(data_root) / "complete"
1052+
1053+
# Ensure the test directory exists
1054+
assert bids_dir.exists()
1055+
1056+
# test the validator in valid dataset
1057+
call = build_validator_call(bids_dir)
1058+
ret = run_validator(call)
1059+
1060+
assert ret.returncode == 0
1061+
1062+
decoded = ret.stdout.decode("UTF-8")
1063+
1064+
# Get the BIDS validator version
1065+
validator_version = Version(get_bids_validator_version()["ValidatorVersion"])
1066+
# Extract schemaVersion
1067+
schema_version = Version(extract_summary_info(decoded)["SchemaVersion"])
1068+
1069+
# Set baseline versions to compare against
1070+
min_validator_version = Version("2.0.0")
1071+
min_schema_version = Version("0.11.3")
1072+
1073+
assert (
1074+
validator_version >= min_validator_version
1075+
), f"Validator version {validator_version} is less than minimum {min_validator_version}"
1076+
assert (
1077+
schema_version >= min_schema_version
1078+
), f"Schema version {schema_version} is less than minimum {min_schema_version}"
1079+
1080+
10311081
def test_docker():
10321082
"""Verify that docker is installed and the user has permission to run docker images.
10331083

cubids/validator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pathlib
88
import re
99
import subprocess
10+
import warnings
1011

1112
import pandas as pd
1213

@@ -249,7 +250,7 @@ def update_dataset_description(path, new_info):
249250
)
250251
print("Changes saved with DataLad.")
251252
except subprocess.CalledProcessError as e:
252-
print(f"Error running DataLad save: {e}")
253+
warnings.warn(f"Error running DataLad save: {e}")
253254

254255

255256
def bids_validator_version(output, path, write=False):

docs/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ We can accomplish this using the following command:
5151
5252
$ conda install deno
5353
54-
The new schema ``bids-validator`` doesn't need to be installed
54+
The new schema-based ``bids-validator`` doesn't need to be installed
5555
and will be implemented automatically when `cubids validate` is called
5656

5757

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ cubids-copy-exemplars = "cubids.cli:_enter_copy_exemplars"
8686
cubids-undo = "cubids.cli:_enter_undo"
8787
bids-sidecar-merge = "cubids.cli:_enter_bids_sidecar_merge"
8888
cubids-validate = "cubids.cli:_enter_validate"
89+
cubids-bids-version = "cubids.cli:_enter_bids_version"
8990
cubids-datalad-save = "cubids.cli:_enter_datalad_save"
9091
cubids-print-metadata-fields = "cubids.cli:_enter_print_metadata_fields"
9192
cubids-remove-metadata-fields = "cubids.cli:_enter_remove_metadata_fields"

0 commit comments

Comments
 (0)