-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
183 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,9 @@ authors = [{name = "The NiPreps Developers", email = "[email protected]"}] | |
classifiers = [ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
] | ||
dependencies = [ | ||
"fmriprep", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"""Fixtures for the CircleCI tests.""" | ||
|
||
import base64 | ||
import os | ||
|
||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
"""Collect pytest parameters for running tests.""" | ||
parser.addoption( | ||
"--working_dir", | ||
action="store", | ||
default=( | ||
"/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", | ||
default=( | ||
"/usr/local/miniconda/lib/python3.11/site-packages/fmripost_aroma/fmripost_aroma/" | ||
"tests/data/test_data" | ||
), | ||
) | ||
parser.addoption( | ||
"--output_dir", | ||
action="store", | ||
default=( | ||
"/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") | ||
def data_dir(request): | ||
"""Grab data directory.""" | ||
return request.config.getoption("--data_dir") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def working_dir(request): | ||
"""Grab working directory.""" | ||
workdir = request.config.getoption("--working_dir") | ||
os.makedirs(workdir, exist_ok=True) | ||
return workdir | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def output_dir(request): | ||
"""Grab output directory.""" | ||
outdir = request.config.getoption("--output_dir") | ||
os.makedirs(outdir, exist_ok=True) | ||
return outdir | ||
|
||
|
||
@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 | ||
LICENSE_CODE = ( | ||
"bWF0dGhldy5jaWVzbGFrQHBzeWNoLnVjc2IuZWR1CjIwNzA2CipDZmVWZEg1VVQ4clkKRlNCWVouVWtlVElDdwo=" | ||
) | ||
with open(FS_LICENSE, "w") as f: | ||
f.write(base64.b64decode(LICENSE_CODE).decode()) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def base_config(): | ||
from fmripost_aroma.tests.tests import mock_config | ||
|
||
return mock_config | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def base_parser(): | ||
from argparse import ArgumentParser | ||
|
||
parser = ArgumentParser(description="Test parser") | ||
return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python3 | ||
"""Run tests locally by calling Docker.""" | ||
import argparse | ||
import os | ||
import subprocess | ||
|
||
|
||
def _get_parser(): | ||
"""Parse command line inputs for tests. | ||
Returns | ||
------- | ||
parser.parse_args() : argparse dict | ||
""" | ||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
"-k", | ||
dest="test_regex", | ||
metavar="PATTERN", | ||
type=str, | ||
help="Test pattern.", | ||
required=False, | ||
default=None, | ||
) | ||
parser.add_argument( | ||
"-m", | ||
dest="test_mark", | ||
metavar="LABEL", | ||
type=str, | ||
help="Test mark label.", | ||
required=False, | ||
default=None, | ||
) | ||
return parser | ||
|
||
|
||
def run_command(command, env=None): | ||
"""Run a given shell command with certain environment variables set. | ||
Keep this out of the real xcp_d code so that devs don't need to install ASLPrep to run tests. | ||
""" | ||
merged_env = os.environ | ||
if env: | ||
merged_env.update(env) | ||
|
||
process = subprocess.Popen( | ||
command, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
shell=True, | ||
env=merged_env, | ||
) | ||
while True: | ||
line = process.stdout.readline() | ||
line = str(line, "utf-8")[:-1] | ||
print(line) | ||
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()}" | ||
) | ||
|
||
|
||
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 " | ||
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 " | ||
) | ||
if test_regex: | ||
run_str += f"-k {test_regex} " | ||
elif test_mark: | ||
run_str += f"-rP -o log_cli=true -m {test_mark} " | ||
|
||
run_command(run_str) | ||
|
||
|
||
def _main(argv=None): | ||
"""Run the tests.""" | ||
options = _get_parser().parse_args(argv) | ||
kwargs = vars(options) | ||
run_tests(**kwargs) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
File renamed without changes.
This file was deleted.
Oops, something went wrong.