Skip to content

Commit

Permalink
[FIX] extract tests (#107)
Browse files Browse the repository at this point in the history
* extract tests

* run on proper folder

* clean

* rm scope fixture
  • Loading branch information
Remi-Gau authored Jan 10, 2025
1 parent 5234597 commit 3a4183e
Show file tree
Hide file tree
Showing 642 changed files with 7,627 additions and 90 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -35,14 +32,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
shell: bash {0}
run: python -c "import sys; print(sys.version)"
- name: Install pybids-reports
shell: bash {0}
run: pip install .[tests]
run: pip install tox
- name: Run tests
shell: bash {0}
run: pytest --pyargs bids.ext.reports --doctest-modules --cov=bids.ext.reports
run: tox run -e test -- tests
- name: Upload coverage to CodeCov
uses: codecov/codecov-action@v5
if: success()
11 changes: 2 additions & 9 deletions .github/workflows/testing_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.12']
python-version: ['3.13']
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
defaults:
Expand All @@ -35,19 +35,12 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
shell: bash {0}
run: python -c "import sys; print(sys.version)"
- name: Install bids examples
run: git clone https://github.com/bids-standard/bids-examples.git
- name: Install pybids-reports
shell: bash {0}
run: pip install .
- name: Info CLI
shell: bash {0}
run: |
pybids_reports --version
pybids_reports --help
- name: Run test for CLI
shell: bash {0}
run: |
bash tools/run_on_examples.sh
run: bash tools/run_on_examples.sh
47 changes: 8 additions & 39 deletions bids/ext/reports/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from __future__ import annotations

import json
import os.path as op
from collections import Counter
from pathlib import Path
from typing import Any

from bids.layout import BIDSFile, BIDSLayout
Expand Down Expand Up @@ -48,17 +48,17 @@ class BIDSReport:
supported.
"""

def __init__(self, layout: BIDSLayout, config: None | str | dict[str, dict[str, str]] = None):
def __init__(
self, layout: BIDSLayout, config: None | str | Path | dict[str, dict[str, str]] = None
):
self.layout = layout
if config is None:
config = op.join(
op.dirname(op.abspath(__file__)),
"config",
"converters.json",
)
config = Path(__file__).absolute().parent / "templates" / "config" / "converters.json"

if isinstance(config, str):
with open(config) as fobj:
config = Path(config)
if isinstance(config, Path):
with config.open() as fobj:
config = json.load(fobj)

if not isinstance(config, dict):
Expand All @@ -85,22 +85,6 @@ def generate_from_files(self, files: list[BIDSFile]) -> Counter[str]:
pattern is most likely the most complete. In cases where the
file list contains multiple protocols, each pattern will need to be
inspected manually.
Examples
--------
>>> from os.path import join
>>> from bids.layout import BIDSLayout
>>> from bids.reports import BIDSReport
>>> from bids.tests import get_test_data_path
>>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
>>> report = BIDSReport(layout)
>>> files = layout.get(session='01', extension=['.nii.gz', '.nii'])
>>> counter = report.generate_from_files(files)
Number of patterns detected: 1
Remember to double-check everything and to replace <deg> with a degree symbol.
>>> counter.most_common()[0][0] # doctest: +ELLIPSIS
'In session 01, MR data were...'
"""
descriptions = []

Expand Down Expand Up @@ -155,21 +139,6 @@ def generate(self, **kwargs: Any) -> Counter[str]:
pattern is most likely the most complete. In cases where the
dataset contains multiple protocols, each pattern will need to be
inspected manually.
Examples
--------
>>> from os.path import join
>>> from bids.layout import BIDSLayout
>>> from bids.reports import BIDSReport
>>> from bids.tests import get_test_data_path
>>> layout = BIDSLayout(join(get_test_data_path(), 'synthetic'))
>>> report = BIDSReport(layout)
>>> counter = report.generate(session='01')
Number of patterns detected: 1
Remember to double-check everything and to replace <deg> with a degree symbol.
>>> counter.most_common()[0][0] # doctest: +ELLIPSIS
'In session 01, MR data were...'
"""
descriptions = []

Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
]
dependencies = [
"chevron",
"pybids>=0.15",
"pybids>=0.18",
"nibabel",
"num2words",
"rich"
Expand Down Expand Up @@ -91,7 +91,7 @@ target-version = ['py39']

[tool.codespell]
ignore-words-list = "te"
skip = "./.git,bids/ext/reports/tests/data/*"
skip = "./.git,tests/data/*"

[tool.coverage.paths]
source = [
Expand All @@ -101,6 +101,10 @@ source = [

[tool.coverage.report]
include_namespace_packages = true
# Regexes for lines to exclude from consideration
omit = [
"*/templates/*"
]

[tool.hatch.build.hooks.vcs]
version-file = "bids/ext/reports/_version.py"
Expand Down Expand Up @@ -137,7 +141,7 @@ module = [
]

[tool.pytest.ini_options]
addopts = "-ra --strict-config --strict-markers --doctest-modules --showlocals -s -vv --durations=0"
addopts = "-ra --strict-config --strict-markers --showlocals -s -vv --durations=0"
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
junit_family = "xunit2"
minversion = "6.0"
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 14 additions & 10 deletions bids/ext/reports/tests/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@
from __future__ import annotations

import json
from os.path import abspath, join
from pathlib import Path

import nibabel as nib
import pytest
from bids.layout import BIDSLayout
from bids.tests import get_test_data_path


@pytest.fixture(scope="module")
def testdataset():
@pytest.fixture
def data_path():
return Path(__file__).parent / "data"


@pytest.fixture
def testdataset(data_path):
"""Path to a BIDS dataset for testing."""
data_dir = join(get_test_data_path(), "synthetic")
data_dir = data_path / "synthetic"
return data_dir


@pytest.fixture(scope="module")
@pytest.fixture
def testlayout(testdataset):
"""A BIDSLayout for testing."""
return BIDSLayout(testdataset)


@pytest.fixture(scope="module")
@pytest.fixture
def testimg(testlayout):
"""A Nifti1Image for testing."""
func_files = testlayout.get(
Expand All @@ -37,7 +41,7 @@ def testimg(testlayout):
return nib.load(func_files[0].path)


@pytest.fixture(scope="module")
@pytest.fixture
def testdiffimg(testlayout):
"""A Nifti1Image for testing."""
dwi_files = testlayout.get(
Expand All @@ -49,10 +53,10 @@ def testdiffimg(testlayout):
return nib.load(dwi_files[0].path)


@pytest.fixture(scope="module")
@pytest.fixture
def testconfig():
"""The standard config file for testing."""
config_file = abspath(join(get_test_data_path(), "../../reports/config/converters.json"))
config_file = Path(__file__).parent / "config" / "converters.json"
with open(config_file) as fobj:
config = json.load(fobj)
return config
Expand Down
2 changes: 2 additions & 0 deletions tests/data/ds000117/.bidsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run-*_echo-*_FLASH.json
**/sub-*_ses-mri_run-*_echo-*_FLASH.nii.gz
14 changes: 14 additions & 0 deletions tests/data/ds000117/CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Revision history for OpenfMRI dataset ds000117

1.0.0 2017-11-08

- Converted to BIDS format
- Changed subject order (see README)

0.1.1 2016-09-17

- Replaced ds117_R0.1.0/sub004/MEG/run_02_sss.fif and ds117_R0.1.0/sub006/MEG/run_03_sss.fif since the original versions were corrupted

0.1.0 2014-11-03

- Initial Release
89 changes: 89 additions & 0 deletions tests/data/ds000117/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
This dataset was obtained from the OpenfMRI project (http://www.openfmri.org).
Accession #: ds000117
Description: Multi-subject, multi-modal (sMRI+fMRI+MEG+EEG) neuroimaging dataset on face recognition

Please cite the following references if you use these data:

A multi-subject, multi-modal human neuroimaging dataset

Wakeman, D.G. & Henson, R.N. (2015). A multi-subject, multi-modal human neuroimaging dataset. Sci. Data 2:150001 doi: 10.1038/sdata.2015.1


Multi-subject, multi-modal (sMRI+fMRI+MEG+EEG) neuroimaging dataset on face recognition
==================================================================================

Please note that the subject ordering has changed since version 0.1.x (non-BIDS) of this
dataset. Additionally, three subjects have been left out. The mapping is as follows:
0.1.x: 02 03 05 14 08 09 10 11 12 15 16 17 18 23 24 25
current: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16

func/
-----
The experiment began at the third nifti volume (corresponding to 5 ignored scans: 3 forced siemens dummies (no files) and 2 included in the data).

meg/
----
Three anatomical fiducials were digitized for aligning the MEG with the MRI: the nasion
(lowest depression between the eyes) and the left and right ears (lowest depression
between the tragus and the helix, above the tragus). This procedure is illustrated here:
http://neuroimage.usc.edu/brainstorm/CoordinateSystems#Subject_Coordinate_System_.28SCS_.2F_CTF.29
and in task-facerecognition_fidinfo.pdf

The following triggers are included in the .fif files and are also used in the “trigger” column of the meg and bold events files:

Trigger Label Simplified Label

5 Initial Famous Face FAMOUS
6 Immediate Repeat Famous Face FAMOUS
7 Delayed Repeat Famous Face FAMOUS
13 Initial Unfamiliar Face UNFAMILIAR
14 Immediate Repeat Unfamiliar Face UNFAMILIAR
15 Delayed Repeat Unfamiliar Face UNFAMILIAR
17 Initial Scrambled Face SCRAMBLED
18 Immediate Repeat Scrambled Face SCRAMBLED
19 Delayed Repeat Scrambled Face SCRAMBLED

stimuli/meg/
------------
The .bmp files correspond to those described in the text. There are 6 additional images in this directory, which were used in the practice experiment to familiarize participants with the task.

stimuli/mri/
------------
The .bmp files correspond to those described in the text.


If you wish to publish any of these data, please acknowledge Daniel Wakeman and Richard Henson. The data has been published so far in:

Wakeman, D.G. & Henson, R.N. (2015). A multi-subject, multi-modal human neuroimaging dataset. Sci. Data 2:150001 doi: 10.1038/sdata.2015.1

Henson, R.N., Wakeman, D.G., Litvak, V. & Friston, K.J. (2011). A Parametric Empirical Bayesian framework for the EEG/MEG inverse problem: generative models for multisubject and multimodal integration. Frontiers in Human Neuroscience, 5, 76, 1-16.

Henson, R.N., Wakeman, D.G., Phillips, C. & Rowe, J. (2012). Effective Connectivity between OFA and FFA during face perception: DCM of evoked MEG, EEG and fMRI responses. HBM2012 Abstract.


### Comments added by Openfmri Curators ###
===========================================

General Comments
----------------


Defacing
--------
Defacing was performed by the submitter

Quality Control
---------------
Mriqc was run on the dataset. Results are located in derivatives/mriqc. Learn more about it here: https://mriqc.readthedocs.io/en/latest/

Where to discuss the dataset
----------------------------
1) www.openfmri.org/dataset/ds000117/ See the comments section at the bottom of the dataset
page.
2) www.neurostars.org Please tag any discussion topics with the tags openfmri and ds000117.
3) Send an email to [email protected]. Please include the accession number in
your email.

Known Issues
------------
N/A
9 changes: 9 additions & 0 deletions tests/data/ds000117/acq-epi_T1w.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"RepetitionTime": 2,
"EchoTime": 0.095,
"FlipAngle": 90,
"Manufacturer": "Siemens",
"ManufacturersModelName": "TIM TRIO",
"MagneticFieldStrength": 3,
"PulseSequenceType": "EPI"
}
10 changes: 10 additions & 0 deletions tests/data/ds000117/acq-mprage_T1w.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"RepetitionTime": 2.25,
"EchoTime": 0.00298,
"InversionTime": 0.9,
"FlipAngle": 9,
"Manufacturer": "Siemens",
"ManufacturersModelName": "TIM TRIO",
"MagneticFieldStrength": 3,
"PulseSequenceType": "MPRAGE"
}
10 changes: 10 additions & 0 deletions tests/data/ds000117/dataset_description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"BIDSVersion": "1.0.2",
"License": "CC0",
"Name": "A multi-subject, multi-modal human neuroimaging dataset",
"Authors": ["Wakeman, DG", "Henson, RN"],
"Acknowledgements": "This work was supported by the UK Medical Research Council (MC_A060_5PR10) and Elekta Ltd. We would also like to acknowledge the contribution of Andre van der Kouwe and the A.A. Martinos Center for Biomedical Imaging (MGH) for providing the Multi-Echo FLASH sequences used in this work.",
"HowToAcknowledge": "Cite this paper: https://www.ncbi.nlm.nih.gov/pubmed/25977808 and consider including the following message: 'This data was obtained from the OpenfMRI database. Its accession number is ds000117'",
"ReferencesAndLinks": ["https://www.ncbi.nlm.nih.gov/pubmed/25977808", "https://openfmri.org/dataset/ds000117/"],
"Funding": ["UK Medical Research Council (MC_A060_5PR10)","Elekta Ltd."]
}
18 changes: 18 additions & 0 deletions tests/data/ds000117/participants.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
participant_id age sex first_ses
sub-01 31 M meg
sub-02 25 M meg
sub-03 30 M meg
sub-04 26 F meg
sub-05 23 F meg
sub-06 26 M meg
sub-07 31 F meg
sub-08 26 M meg
sub-09 29 M meg
sub-10 23 M meg
sub-11 24 F meg
sub-12 24 F meg
sub-13 25 F meg
sub-14 24 F mri
sub-15 30 M mri
sub-16 25 M mri
sub-emptyroom n/a n/a n/a
Loading

0 comments on commit 3a4183e

Please sign in to comment.