Skip to content

Commit d7c1dd5

Browse files
author
Benedikt Ehinger
committed
cleaned up tests a bit
1 parent a2ab2e3 commit d7c1dd5

File tree

4 files changed

+67
-103
lines changed

4 files changed

+67
-103
lines changed

tests/path_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ def get_root_paths(test_file: str):
1818
}
1919

2020

21+
22+
def monkeypatch_paths(monkeypatch,paths):
23+
monkeypatch.setattr("lslautobids.config_globals.project_root", paths["project_root"])
24+
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.project_root", paths["project_root"])
25+
monkeypatch.setattr("lslautobids.generate_dataset_json.project_root", paths["project_root"])
26+
monkeypatch.setattr("lslautobids.main.project_root", paths["project_root"])
27+
monkeypatch.setattr("lslautobids.processing_new_files.project_root", paths["project_root"])
28+
29+
monkeypatch.setattr("lslautobids.config_globals.bids_root", paths["bids_root"])
30+
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.bids_root", paths["bids_root"])
31+
monkeypatch.setattr("lslautobids.main.bids_root", paths["bids_root"])
32+
33+
monkeypatch.setattr("lslautobids.config_logger.bids_root", paths["bids_root"])
34+
monkeypatch.setattr("lslautobids.config_globals.project_other_root", paths["project_other_root"])
35+
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.project_other_root", paths["project_other_root"])

tests/test_main_functionality/test_main_functionality.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sys.path.insert(0, PROJECT_ROOT)
1313

1414

15-
from path_config import get_root_paths
15+
from path_config import get_root_paths,monkeypatch_paths
1616
#from test_utils.path_config import DummyCLIArgs
1717
# Print test file name for traceability
1818
test_file_name = os.path.basename(__file__)
@@ -26,50 +26,22 @@ def test_process_main_functionality(setup_project, monkeypatch):
2626
"""
2727
Expect the main pipeline to raise RuntimeError when duplicate files are found.
2828
"""
29-
project_name = setup_project
29+
project_name = setup_project # fixture via pytest
3030
paths = get_root_paths(__file__)
31-
print("ZZZ - main functionality")
3231

33-
print(paths)
34-
35-
36-
#importlib.reload(lslautobids.config_globals)
37-
#importlib.reload(lslautobids.main)
38-
39-
monkeypatch.setattr("lslautobids.config_globals.project_root", paths["project_root"])
40-
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.project_root", paths["project_root"])
41-
monkeypatch.setattr("lslautobids.generate_dataset_json.project_root", paths["project_root"])
42-
monkeypatch.setattr("lslautobids.main.project_root", paths["project_root"])
43-
monkeypatch.setattr("lslautobids.processing_new_files.project_root", paths["project_root"])
44-
45-
monkeypatch.setattr("lslautobids.config_globals.bids_root", paths["bids_root"])
46-
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.bids_root", paths["bids_root"])
47-
monkeypatch.setattr("lslautobids.main.bids_root", paths["bids_root"])
32+
monkeypatch_paths(monkeypatch,paths)
4833

49-
monkeypatch.setattr("lslautobids.config_logger.bids_root", paths["bids_root"])
50-
monkeypatch.setattr("lslautobids.config_globals.project_other_root", paths["project_other_root"])
51-
monkeypatch.setattr("lslautobids.convert_to_bids_and_upload.project_other_root", paths["project_other_root"])
5234

53-
#lslautobids.config_globals.project_root = paths["project_root"]
54-
#lslautobids.config_globals.bids_root = paths["bids_root"]
55-
#lslautobids.config_globals.project_other_root = paths["project_other_root"]
56-
#project_toml_path = os.path.join(paths["project_root"], project_name, f"{project_name}_config.toml")
57-
5835
# Reset sys.argv to something that lslautobids.main.main() expects
36+
# this effectively removes the -c from setup_project
5937
sys.argv = [
6038
"lslautobids.main",
6139
"-p", project_name,
6240
# other args expected by lslautobids.main.main
6341
]
64-
65-
# dummy_cli_args = DummyCLIArgs()
66-
# monkeypatch.setattr("lslautobids.config_globals.cli_args", dummy_cli_args)
67-
68-
# Import and run main pipeline, expect a RuntimeError
6942

43+
# run once
7044
import lslautobids.main
71-
72-
#with pytest.raises(SystemExit, match="Duplicate file detected. Please check the file manually."):
7345
lslautobids.main.main()
7446

7547
# add a subject

tests/test_old_suffix/test_aold_suffix.py

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import sys
3+
import pytest
4+
import yaml
5+
6+
7+
import importlib
8+
# Compute project root (two levels up from current test.py)
9+
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
10+
if PROJECT_ROOT not in sys.path:
11+
sys.path.insert(0, PROJECT_ROOT)
12+
13+
from path_config import get_root_paths,monkeypatch_paths
14+
#from test_utils.path_config import DummyCLIArgs
15+
16+
# Print test file name for traceability
17+
test_file_name = os.path.basename(__file__)
18+
print(f" Running tests in {test_file_name}")
19+
20+
21+
22+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
23+
def test_process_new_files_with_old_suffix(setup_project, monkeypatch):
24+
"""
25+
Expect the main pipeline to raise RuntimeError when duplicate files are found.
26+
"""
27+
project_name = setup_project
28+
paths = get_root_paths(__file__)
29+
30+
monkeypatch_paths(monkeypatch,paths)
31+
32+
# Reset sys.argv to something that lslautobids.main.main() expects
33+
sys.argv = [
34+
"lslautobids.main",
35+
"-p", project_name,
36+
# other args expected by lslautobids.main.main
37+
]
38+
39+
40+
import lslautobids.main
41+
42+
# Import and run main pipeline, expect a RuntimeError
43+
with pytest.raises(SystemExit, match="Duplicate file detected. Please check the file manually."):
44+
lslautobids.main.main()
45+
46+
47+

0 commit comments

Comments
 (0)