Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags to run CI tests locally #596

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ def pytest_addoption(parser):
action="store",
help="Directory for (only-read) inputs for tests",
)
parser.addoption(
"--no-gpu",
action="store_true",
help="""To run tests on cpu. Default is False.
To use carefully, only to run tests locally. Should not be used in final CI tests.
Concretely, the tests won't fail if gpu option is false in the output MAPS whereas
it is true in the reference MAPS.""",
)
parser.addoption(
"--adapt-base-dir",
action="store_true",
help="""To virtually change the base directory in the paths stored in the MAPS of the CI data.
Default is False.
To use carefully, only to run tests locally. Should not be used in final CI tests.
Concretely, the tests won't fail if only the base directories differ in the paths stored
in the output and reference MAPS.""",
)


@pytest.fixture
def cmdopt(request):
config_param = {}
config_param["input"] = request.config.getoption("--input_data_directory")
config_param["no-gpu"] = request.config.getoption("--no-gpu")
config_param["adapt-base-dir"] = request.config.getoption("--adapt-base-dir")
return config_param
14 changes: 14 additions & 0 deletions tests/test_train_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def test_train_ae(cmdopt, tmp_path, test_name):
else:
raise NotImplementedError(f"Test {test_name} is not implemented.")

if cmdopt["no-gpu"]:
test_input.append("--no-gpu")

if tmp_out_dir.is_dir():
shutil.rmtree(tmp_out_dir)

Expand All @@ -101,6 +104,17 @@ def test_train_ae(cmdopt, tmp_path, test_name):

if test_name == "patch_multi_ae":
json_data_out["multi_network"] = True
if cmdopt["no-gpu"]:
json_data_ref["gpu"] = False
if cmdopt["adapt-base-dir"]:
base_dir = base_dir.resolve()
ref_base_dir = Path(json_data_ref["caps_directory"]).parents[2]
json_data_ref["caps_directory"] = str(
base_dir / Path(json_data_ref["caps_directory"]).relative_to(ref_base_dir)
)
json_data_ref["tsv_path"] = str(
base_dir / Path(json_data_ref["tsv_path"]).relative_to(ref_base_dir)
)
assert json_data_out == json_data_ref # ["mode"] == mode

assert compare_folders(
Expand Down
Loading