Skip to content

Commit

Permalink
add flags to run functional tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultdvx committed May 28, 2024
1 parent 4281c73 commit effeee2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ def pytest_addoption(parser):
Concretely, the tests won't fail if gpu option if false in the output MAPS whereas
it should be true.""",
)
parser.addoption(
"--adapt-base-dir",
action="store_true",
help="""To virtually change the base directory in the paths stored in MAPS. 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 directory differs in the paths stored
in the MAPS.""",
)


@pytest.fixture
def cmdopt(request):
config_param = {}
config_param["input"] = request.config.getoption("--input_data_directory")
config_param["simulate gpu"] = request.config.getoption("--simulate-gpu")
config_param["adapt base dir"] = request.config.getoption("--adapt-base-dir")
return config_param
15 changes: 14 additions & 1 deletion tests/test_train_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_name(request):


def test_train_ae(cmdopt, tmp_path, test_name):
base_dir = Path(cmdopt["input"])
base_dir = Path(cmdopt["input"]).resolve()
input_dir = base_dir / "train" / "in"
ref_dir = base_dir / "train" / "ref"
tmp_out_dir = base_dir / "train" / "out"
Expand Down 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["simulate gpu"]:
test_input.append("--no-gpu")

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

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

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

assert compare_folders(
Expand Down

0 comments on commit effeee2

Please sign in to comment.