Skip to content

Commit

Permalink
TEST: Expand tests to prepare for refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Dec 15, 2023
1 parent 9b6f39b commit 6dd3794
Showing 1 changed file with 99 additions and 6 deletions.
105 changes: 99 additions & 6 deletions bids-validator/bids_validator/test_bids_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,107 @@ def _gather_test_files(dspath, exclude_keywords):
files = _gather_test_files(dspath, EXCLUDE_KEYWORDS)


@pytest.mark.parametrize('fname', files)
def test_is_bids(validator, fname):
"""Test that is_bids returns true for each file in a valid BIDS dataset."""
assert validator.is_bids(fname)


@pytest.fixture(scope='module')
def validator():
"""Return a BIDSValidator instance."""
validator = BIDSValidator()
return validator


@pytest.mark.parametrize('fname', files)
def test_datasets(validator, fname):
"""Test that is_bids returns true for each file in a valid BIDS dataset."""
assert validator.is_bids(fname)


@pytest.mark.parametrize('fname, matches', [
('/T1w.json', True),
('/dataset_description.json', True),
('/README', True),
('/CHANGES', True),
('/participants.tsv', True),
('/sub-01/anat/sub-01_T1w.nii.gz', False),
])
def test_top_level(validator, fname, matches):
"""Test that is_top_level returns true for top-level files."""
assert validator.is_top_level(fname) is matches


@pytest.mark.parametrize('fname, matches', [
('/sourcedata/unstructured_data.nii.gz', True),
('/sourcedata/dicom_dir/xyz.dcm', True),
('/code/my_analysis/analysis.py', True),
('/derivatives/preproc/sub-01/anat/sub-01_desc-preproc_T1w.nii.gz', True),
('/stimuli/pic.jpg', True),
('/sub-01/anat/sub-01_T1w.nii.gz', False),
])
def test_associated_data(validator, fname, matches):
"""Test that is_associated_data returns true for associated data."""
assert validator.is_associated_data(fname) is matches


@pytest.mark.parametrize('fname, matches', [
('/sub-01/ses-1/sub-01_ses-1_scans.tsv', True),
('/sub-01/ses-1/sub-01_ses-1_scans.json', True),
('/sub-01/sub-01_scans.tsv', True),
('/sub-01/sub-01_scans.json', True),
('/sub-01/ses-1/sub-01_ses-1_task-rest_bold.json', True),
('/sub-01/sub-01_task-rest_bold.json', True),
('/sub-01/ses-1/sub-01_ses-1_asl.json', True),
('/sub-01/sub-01_asl.json', True),
('/sub-01/ses-1/sub-01_ses-1_pet.json', True),
('/sub-01/sub-01_pet.json', True),
('/sub-01/ses-1/sub-01_ses-1_proc-test_channels.tsv', True),
('/sub-01/ses-1/sub-01_ses-1_channels.json', True),
('/sub-01/sub-01_proc-test_channels.tsv', True),
('/sub-01/sub-01_channels.json', True),
('/sub-01/ses-1/sub-01_ses-1_space-CapTrak_electrodes.tsv', True),
('/sub-01/ses-1/sub-01_ses-1_coordsystem.json', True),
('/sub-01/sub-01_space-CapTrak_electrodes.tsv', True),
('/sub-01/sub-01_coordsystem.json', True),
('/sub-01/ses-1/sub-01_ses-1_motion.json', True),
('/sub-01/sub-01_motion.json', True),
('/sub-01/ses-1/sub-01_ses-1_TEM.json', True),
('/sub-01/sub-01_TEM.json', True),
('/sub-01/ses-1/sub-01_ses-1_nirs.json', True),
('/sub-01/sub-01_nirs.json', True),
# Mismatch sessions
('/sub-01/sub-01_ses-1_scans.tsv', False),
('/sub-01/sub-01_ses-1_scans.json', False),
('/sub-01/ses-1/sub-01_ses-2_scans.tsv', False),
# File-level
('/sub-01/ses-1/func/sub-01_ses-1_task-rest_bold.nii.gz', False),
('/sub-01/anat/sub-01_T1w.nii.gz', False),
])
def test_session_level(validator, fname, matches):
"""Test that is_session_level returns true for session level files."""
assert validator.is_session_level(fname) is matches


@pytest.mark.parametrize('fname, matches', [
('/sub-01/sub-01_sessions.tsv', True),
('/sub-01/sub-01_sessions.json', True),
('/sub-01/anat/sub-01_T1w.nii.gz', False),
])
def test_subject_level(validator, fname, matches):
"""Test that is_subject_level returns true for subject level files."""
assert validator.is_subject_level(fname) is matches


@pytest.mark.parametrize('fname, matches', [
('/phenotype/measure.tsv', True),
('/phenotype/measure.json', True),
('/sub-01/anat/sub-01_T1w.nii.gz', False),
])
def test_phenotpic(validator, fname, matches):
"""Test that is_phenotypic returns true for phenotypic files."""
assert validator.is_phenotypic(fname) is matches


@pytest.mark.parametrize('fname, matches', [
('/sub-01/ses-1/func/sub-01_ses-1_task-rest_bold.nii.gz', True),
('/sub-01/anat/sub-01_T1w.nii.gz', True),
])
def test_file_level(validator, fname, matches):
"""Test that is_file returns true for file level files."""
assert validator.is_file(fname) is matches

0 comments on commit 6dd3794

Please sign in to comment.