Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ test = [
"pytest >=8",
"pytest-cov >=5",
"coverage[toml] >=7.2",
"datalad >=1.1",
"cattrs>=24.1.3",
]
types = [
Expand Down
42 changes: 0 additions & 42 deletions src/bids_validator/test_bids_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,10 @@

"""

import os

import datalad.api
import pytest

from bids_validator import BIDSValidator

HOME = os.path.expanduser('~')

TEST_DATA_DICT = {
'eeg_matchingpennies': 'https://gin.g-node.org/sappelhoff/eeg_matchingpennies',
}

EXCLUDE_KEYWORDS = ['git', 'datalad', 'sourcedata', 'bidsignore']


def _download_test_data(test_data_dict: dict[str, str], dsname: str) -> str:
"""Download test data using datalad."""
url = test_data_dict[dsname]
dspath = os.path.join(HOME, dsname)
datalad.api.clone(source=url, path=dspath)
return dspath


def _gather_test_files(dspath: str, exclude_keywords: list[str]) -> list[str]:
"""Get test files from dataset path, relative to dataset."""
files = []
for r, _, f in os.walk(dspath):
for file in f:
fname = os.path.join(r, file)
fname = fname.replace(dspath, '')
if not any(keyword in fname for keyword in exclude_keywords):
files.append(fname)

return files


dspath = _download_test_data(TEST_DATA_DICT, 'eeg_matchingpennies')
files = _gather_test_files(dspath, EXCLUDE_KEYWORDS)


@pytest.fixture(scope='module')
def validator() -> BIDSValidator:
Expand All @@ -53,12 +17,6 @@ def validator() -> BIDSValidator:
return validator


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


@pytest.mark.parametrize(
'fname',
[
Expand Down
31 changes: 31 additions & 0 deletions tests/test_legacy_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from pathlib import Path

import pytest

from bids_validator import BIDSValidator


@pytest.fixture(scope='module')
def validator() -> BIDSValidator:
return BIDSValidator()


@pytest.mark.parametrize(
'example',
[
'ds001',
'ds000117',
'pet001',
'eeg_matchingpennies',
'dwi_deriv',
],
)
def test_example(validator: BIDSValidator, examples: Path, example: str) -> None:
ds = examples / example
for root, _dirs, files in os.walk(ds):
for file in files:
fname = str(Path(root).joinpath(file).relative_to(ds).as_posix())
if fname == '.bidsignore':
continue
assert validator.is_bids(f'/{fname}')
7 changes: 1 addition & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,9 @@ deps =
pre: git+https://github.com/bids-standard/bids-specification.git\#subdirectory=tools/schemacode

commands =
# Avoid SyntaxWarning being promoted to SyntaxError in Python 3.14, Datalad up to 1.3.2.
python -c 'import datalad'
coverage erase
coverage run -p -m bids_validator tests/data/bids-examples/ds000117
python -m pytest --doctest-modules --cov . --cov-append --cov-report term \
python -m pytest --doctest-modules --cov . --cov-report xml --cov-report term \
min: -Wignore \
--junitxml=test-results.xml {posargs}
coverage xml

[testenv:style{,-fix}]
description = Check and attempt to fix style
Expand Down
Loading
Loading