Skip to content

Commit 16d9cf5

Browse files
author
Benedikt Ehinger
committed
fix the tests, simplified the setup greatly. monkeypatching sucks
1 parent 918ca7a commit 16d9cf5

32 files changed

+205
-187
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jsonschema
88
empty_log_process_temp.py
99

1010
tests/**/bids/
11-
tests/testcases/test_main_functionality/data/projects/test-project/sub-100
11+
tests/test_main_functionality/data/projects/test-project/sub-100
1212
# Byte-compiled / optimized / DLL files
1313
__pycache__/
1414
*.py[cod]

lslautobids/config_globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def parse_yaml_file(yaml_file):
5656

5757
# Determine config paty based on context
5858
if "pytest" in sys.modules:
59-
config_file = os.path.join(os.path.expanduser("~"), ".config/lslautobids/test-autobids_config.yaml")
59+
#config_file = os.path.join(os.path.expanduser("~"), ".config/lslautobids/test-autobids_config.yaml")
60+
config_file = "tests/pytest-autobids_config.yaml"
6061
else:
6162
config_file = os.path.join(os.path.expanduser("~"), ".config/lslautobids/autobids_config.yaml")
6263
config = parse_yaml_file(config_file)
Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import os
2-
import sys
31
import pytest
4-
import yaml
5-
import shutil
6-
7-
# Compute project root (two levels up from current test.py)
8-
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
2+
import sys,os
3+
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
94
if PROJECT_ROOT not in sys.path:
105
sys.path.insert(0, PROJECT_ROOT)
6+
import yaml
117

12-
from test_utils.path_config import get_root_paths
13-
from test_utils.path_config import DummyCLIArgs
14-
# Print test file name for traceability
15-
test_file_name = os.path.basename(__file__)
16-
print(f" Running tests in {test_file_name}")
17-
8+
from path_config import get_root_paths
189

1910

11+
# Dummy CLI argument simulation
12+
class DummyCLIArgs:
13+
def __init__(self):
14+
self.project_name = "test-project"
15+
self.yes = True
16+
self.redo_bids_conversion = False
17+
self.redo_other_pc = False
18+
self.push_to_dataverse = False
19+
def init(self, args):
20+
# you can store the args or ignore
21+
pass
2022

2123
@pytest.fixture(scope="function")
2224
def setup_project(monkeypatch):
@@ -29,13 +31,15 @@ def setup_project(monkeypatch):
2931
project_name = dummy_cli_args.project_name
3032

3133
# Ensure directory exists
32-
os.makedirs(paths["project_root"], exist_ok=True)
34+
#os.makedirs(paths["project_root"], exist_ok=True)
3335

3436
from lslautobids.gen_project_config import main as gen_project_config_main
3537

3638
# Create dummy user config for the test
37-
config_file_test = os.path.join(os.path.expanduser("~"),'.config/lslautobids/test-autobids_config.yaml')
38-
os.makedirs(os.path.dirname(config_file_test), exist_ok=True)
39+
#config_file_test = os.path.join(os.path.expanduser("~"),'.config/lslautobids/test-autobids_config.yaml')
40+
config_file_test = ("tests/pytest-autobids_config.yaml")
41+
42+
#os.makedirs(os.path.dirname(config_file_test), exist_ok=True)
3943
config_data = {
4044
"PROJECT_ROOT": paths["project_root"],
4145
"BIDS_ROOT": paths["bids_root"],
@@ -67,37 +71,7 @@ def setup_project(monkeypatch):
6771

6872
gen_project_config_main()
6973

70-
return paths, project_name
71-
72-
73-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
74-
def test_process_new_files_with_old_suffix(setup_project, monkeypatch):
75-
"""
76-
Expect the main pipeline to raise RuntimeError when duplicate files are found.
77-
"""
78-
paths, project_name = setup_project
79-
80-
project_toml_path = os.path.join(paths["project_root"], project_name, f"{project_name}_config.toml")
81-
82-
# Reset sys.argv to something that lslautobids.main.main() expects
83-
sys.argv = [
84-
"lslautobids.main",
85-
"-p", project_name,
86-
# other args expected by lslautobids.main.main
87-
]
88-
89-
dummy_cli_args = DummyCLIArgs()
90-
monkeypatch.setattr("lslautobids.config_globals.cli_args", dummy_cli_args)
91-
92-
# Import and run main pipeline, expect a RuntimeError
93-
from lslautobids.main import main as runlslautobids
94-
#with pytest.raises(SystemExit, match="Duplicate file detected. Please check the file manually."):
95-
runlslautobids()
96-
97-
# add a subject
98-
shutil.copytree(os.path.join(paths["project_root"], "copy_later","sub-100"), os.path.join(paths["project_root"], project_name,"sub-100"))
99-
100-
runlslautobids()
101-
102-
74+
yield project_name
10375

76+
# crashdown
77+
#os.remove(config_file_test)

tests/test_utils/path_config.py renamed to tests/path_config.py

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

2020

21-
22-
23-
# Dummy CLI argument simulation
24-
class DummyCLIArgs:
25-
def __init__(self):
26-
self.project_name = "test-project"
27-
self.yes = True
28-
self.redo_bids_conversion = False
29-
self.redo_other_pc = False
30-
self.push_to_dataverse = False
31-
def init(self, args):
32-
# you can store the args or ignore
33-
pass

tests/pytest-autobids_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BIDS_ROOT: /home/behinger/projects/LSLAutoBIDS/tests/data/bids
2+
PROJECT_OTHER_ROOT: /home/behinger/projects/LSLAutoBIDS/tests/data/project_other
3+
PROJECT_ROOT: /home/behinger/projects/LSLAutoBIDS/tests/data/projects

tests/run_all_tests.py.deactivate

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)