diff --git a/src/fmripost_aroma/interfaces/nilearn.py b/src/fmripost_aroma/interfaces/nilearn.py index ce07187..936d8c8 100644 --- a/src/fmripost_aroma/interfaces/nilearn.py +++ b/src/fmripost_aroma/interfaces/nilearn.py @@ -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.', ) @@ -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']) return runtime @@ -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.', ) @@ -84,6 +84,6 @@ def _run_interface(self, runtime): from nilearn.masking import apply_mask 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) return runtime diff --git a/src/fmripost_aroma/tests/conftest.py b/src/fmripost_aroma/tests/conftest.py index 5b6a773..55e57f8 100644 --- a/src/fmripost_aroma/tests/conftest.py +++ b/src/fmripost_aroma/tests/conftest.py @@ -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 diff --git a/src/fmripost_aroma/tests/run_local_tests.py b/src/fmripost_aroma/tests/run_local_tests.py index 3486be1..2216742 100644 --- a/src/fmripost_aroma/tests/run_local_tests.py +++ b/src/fmripost_aroma/tests/run_local_tests.py @@ -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, ) @@ -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) @@ -92,5 +92,5 @@ def _main(argv=None): run_tests(**kwargs) -if __name__ == "__main__": +if __name__ == '__main__': _main() diff --git a/src/fmripost_aroma/tests/tests.py b/src/fmripost_aroma/tests/tests.py index 7662782..e4ac9f1 100644 --- a/src/fmripost_aroma/tests/tests.py +++ b/src/fmripost_aroma/tests/tests.py @@ -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