Skip to content

Commit

Permalink
Fix some style issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed May 9, 2024
1 parent 666a169 commit b500a2d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 61 deletions.
20 changes: 10 additions & 10 deletions src/fmripost_aroma/interfaces/nilearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ class _MeanImageInputSpec(BaseInterfaceInputSpec):
bold_file = File(
exists=True,
mandatory=True,
desc="A 4D BOLD file to process.",
desc='A 4D BOLD file to process.',
)
mask_file = File(
exists=True,
mandatory=True,
desc="A binary brain mask.",
desc='A binary brain mask.',
)
out_file = File(
"mean.nii.gz",
'mean.nii.gz',
usedefault=True,
exists=False,
desc="The name of the mean file to write out. mean.nii.gz by default.",
desc='The name of the mean file to write out. mean.nii.gz by default.',
)


class _MeanImageOutputSpec(TraitedSpec):
out_file = File(
exists=True,
desc="Mean output file.",
desc='Mean output file.',
)


Expand All @@ -51,8 +51,8 @@ def _run_interface(self, runtime):
data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
mean_data = data.mean(axis=0)
mean_img = unmask(mean_data, self.inputs.mask_file)
self._results["out_file"] = os.path.join(runtime.cwd, self.inputs.out_file)
mean_img.to_filename(self._results["out_file"])
self._results['out_file'] = os.path.join(runtime.cwd, self.inputs.out_file)
mean_img.to_filename(self._results['out_file'])

Check warning on line 55 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L51-L55

Added lines #L51 - L55 were not covered by tests

return runtime

Check warning on line 57 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L57

Added line #L57 was not covered by tests

Expand All @@ -61,12 +61,12 @@ class _MedianValueInputSpec(BaseInterfaceInputSpec):
bold_file = File(
exists=True,
mandatory=True,
desc="A 4D BOLD file to process.",
desc='A 4D BOLD file to process.',
)
mask_file = File(
exists=True,
mandatory=True,
desc="A binary brain mask.",
desc='A binary brain mask.',
)


Expand All @@ -84,6 +84,6 @@ def _run_interface(self, runtime):
from nilearn.masking import apply_mask

Check warning on line 84 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L84

Added line #L84 was not covered by tests

data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
self._results["median_value"] = np.median(data)
self._results['median_value'] = np.median(data)

Check warning on line 87 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L86-L87

Added lines #L86 - L87 were not covered by tests

return runtime

Check warning on line 89 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L89

Added line #L89 was not covered by tests
52 changes: 26 additions & 26 deletions src/fmripost_aroma/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,76 @@
def pytest_addoption(parser):
"""Collect pytest parameters for running tests."""
parser.addoption(
"--working_dir",
action="store",
'--working_dir',
action='store',
default=(
"/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/"
"tests/data/test_data/run_pytests/work"
'/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/'
'tests/data/test_data/run_pytests/work'
),
)
parser.addoption(
"--data_dir",
action="store",
'--data_dir',
action='store',
default=(
"/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/"
"tests/data/test_data"
'/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/'
'tests/data/test_data'
),
)
parser.addoption(
"--output_dir",
action="store",
'--output_dir',
action='store',
default=(
"/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/"
"tests/data/test_data/run_pytests/out"
'/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/'
'tests/data/test_data/run_pytests/out'
),
)


# Set up the commandline options as fixtures
@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def data_dir(request):
"""Grab data directory."""
return request.config.getoption("--data_dir")
return request.config.getoption('--data_dir')


@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def working_dir(request):
"""Grab working directory."""
workdir = request.config.getoption("--working_dir")
workdir = request.config.getoption('--working_dir')
os.makedirs(workdir, exist_ok=True)
return workdir


@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def output_dir(request):
"""Grab output directory."""
outdir = request.config.getoption("--output_dir")
outdir = request.config.getoption('--output_dir')
os.makedirs(outdir, exist_ok=True)
return outdir


@pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope='session', autouse=True)
def fslicense(working_dir):
"""Set the FreeSurfer license as an environment variable."""
FS_LICENSE = os.path.join(working_dir, "license.txt")
os.environ["FS_LICENSE"] = FS_LICENSE
FS_LICENSE = os.path.join(working_dir, 'license.txt')
os.environ['FS_LICENSE'] = FS_LICENSE
LICENSE_CODE = (
"bWF0dGhldy5jaWVzbGFrQHBzeWNoLnVjc2IuZWR1CjIwNzA2CipDZmVWZEg1VVQ4clkKRlNCWVouVWtlVElDdwo="
'bWF0dGhldy5jaWVzbGFrQHBzeWNoLnVjc2IuZWR1CjIwNzA2CipDZmVWZEg1VVQ4clkKRlNCWVouVWtlVElDdwo='
)
with open(FS_LICENSE, "w") as f:
with open(FS_LICENSE, 'w') as f:
f.write(base64.b64decode(LICENSE_CODE).decode())


@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def base_config():
from fmripost_aroma.tests.tests import mock_config

return mock_config


@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def base_parser():
from argparse import ArgumentParser

parser = ArgumentParser(description="Test parser")
parser = ArgumentParser(description='Test parser')
return parser
46 changes: 23 additions & 23 deletions src/fmripost_aroma/tests/run_local_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ def _get_parser():
"""
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"-k",
dest="test_regex",
metavar="PATTERN",
'-k',
dest='test_regex',
metavar='PATTERN',
type=str,
help="Test pattern.",
help='Test pattern.',
required=False,
default=None,
)
parser.add_argument(
"-m",
dest="test_mark",
metavar="LABEL",
'-m',
dest='test_mark',
metavar='LABEL',
type=str,
help="Test mark label.",
help='Test mark label.',
required=False,
default=None,
)
Expand All @@ -52,35 +52,35 @@ def run_command(command, env=None):
)
while True:
line = process.stdout.readline()
line = str(line, "utf-8")[:-1]
line = str(line, 'utf-8')[:-1]
print(line)
if line == "" and process.poll() is not None:
if line == '' and process.poll() is not None:
break

if process.returncode != 0:
raise RuntimeError(
f"Non zero return code: {process.returncode}\n" f"{command}\n\n{process.stdout.read()}"
f'Non zero return code: {process.returncode}\n' f'{command}\n\n{process.stdout.read()}'
)


def run_tests(test_regex, test_mark):
"""Run the tests."""
local_patch = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
mounted_code = "/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma"
run_str = "docker run --rm -ti "
run_str += f"-v {local_patch}:{mounted_code} "
run_str += "--entrypoint pytest "
run_str += "nipreps/fmripost_aroma:unstable "
mounted_code = '/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma'
run_str = 'docker run --rm -ti '
run_str += f'-v {local_patch}:{mounted_code} '
run_str += '--entrypoint pytest '
run_str += 'nipreps/fmripost_aroma:unstable '
run_str += (
f"{mounted_code}/fmripost_aroma "
f"--data_dir={mounted_code}/fmripost_aroma/tests/test_data "
f"--output_dir={mounted_code}/fmripost_aroma/tests/pytests/out "
f"--working_dir={mounted_code}/fmripost_aroma/tests/pytests/work "
f'{mounted_code}/fmripost_aroma '
f'--data_dir={mounted_code}/fmripost_aroma/tests/test_data '
f'--output_dir={mounted_code}/fmripost_aroma/tests/pytests/out '
f'--working_dir={mounted_code}/fmripost_aroma/tests/pytests/work '
)
if test_regex:
run_str += f"-k {test_regex} "
run_str += f'-k {test_regex} '
elif test_mark:
run_str += f"-rP -o log_cli=true -m {test_mark} "
run_str += f'-rP -o log_cli=true -m {test_mark} '

run_command(run_str)

Expand All @@ -92,5 +92,5 @@ def _main(argv=None):
run_tests(**kwargs)


if __name__ == "__main__":
if __name__ == '__main__':
_main()
3 changes: 1 addition & 2 deletions src/fmripost_aroma/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
from pathlib import Path
from tempfile import mkdtemp

from toml import loads

from fmripost_aroma.data import load as load_data
from toml import loads


@contextmanager
Expand Down

0 comments on commit b500a2d

Please sign in to comment.