Skip to content

Commit

Permalink
FIX: Avoid cluttering directories with test files
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Oct 2, 2024
1 parent c68b670 commit 161c9b5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
25 changes: 0 additions & 25 deletions nibabies/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,13 @@

import json
from pathlib import Path
from tempfile import TemporaryDirectory

import nibabel as nb
import numpy as np
import pytest

from nibabies.data import load as load_data

FILES = (
'functional.nii',
'anatomical.nii',
'func.dlabel.nii',
'func.dtseries.nii',
'epi.nii',
'T1w.nii',
'func_to_struct.mat',
'atlas.nii',
'label_list.txt',
'sub-01_run-01_echo-1_bold.nii.gz',
'sub-01_run-01_echo-2_bold.nii.gz',
'sub-01_run-01_echo-3_bold.nii.gz',
)


@pytest.fixture(scope='package')
def data_dir():
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
for fname in FILES:
Path.touch(tmp_path / fname)
yield tmp_path


@pytest.fixture(autouse=True)
def _populate_namespace(doctest_namespace, data_dir):
Expand Down
Empty file.
Empty file.
Empty file.
29 changes: 25 additions & 4 deletions nibabies/interfaces/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from shutil import copytree
from tempfile import TemporaryDirectory

import pytest

Expand All @@ -19,17 +20,37 @@ def _chdir(path):
os.chdir(cwd)


@pytest.fixture(scope='module')
DATA_FILES = (
'functional.nii',
'anatomical.nii',
'func.dlabel.nii',
'func.dtseries.nii',
'epi.nii',
'T1w.nii',
'func_to_struct.mat',
'atlas.nii',
'label_list.txt',
'sub-01_run-01_echo-1_bold.nii.gz',
'sub-01_run-01_echo-2_bold.nii.gz',
'sub-01_run-01_echo-3_bold.nii.gz',
)


@pytest.fixture(scope='package')
def data_dir():
return Path(__file__).parent / 'tests' / 'data'
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
for fname in DATA_FILES:
Path.touch(tmp_path / fname)
yield tmp_path


@pytest.fixture(autouse=True)
def _docdir(request, tmp_path):
def _docdir(data_dir, request, tmp_path):
# Trigger ONLY for the doctests.
doctest_plugin = request.config.pluginmanager.getplugin('doctest')
if isinstance(request.node, doctest_plugin.DoctestItem):
copytree(Path(__file__).parent / 'tests' / 'data', tmp_path, dirs_exist_ok=True)
copytree(data_dir, tmp_path, dirs_exist_ok=True)

# Chdir only for the duration of the test.
with _chdir(tmp_path):
Expand Down
Empty file.

0 comments on commit 161c9b5

Please sign in to comment.