|
10 | 10 | from .data import load_data |
11 | 11 |
|
12 | 12 |
|
| 13 | +def get_submod_or_env(dir_name: str, env_var: str) -> Path: |
| 14 | + """Get submodule data path or override from environment variable. |
| 15 | +
|
| 16 | + Signals to skip tests if submodule is not checked out and no variable is set. |
| 17 | + """ |
| 18 | + ret = os.getenv(env_var) |
| 19 | + if not ret: |
| 20 | + data_path = load_data(dir_name) |
| 21 | + if not any(data_path.iterdir()): |
| 22 | + pytest.skip(f'{dir_name} submodule is not checked out') |
| 23 | + return data_path |
| 24 | + return Path(ret) |
| 25 | + |
| 26 | + |
13 | 27 | @pytest.fixture(scope='session') |
14 | 28 | def examples() -> Path: |
15 | 29 | """Get bids-examples from submodule, allow environment variable override.""" |
16 | | - ret = os.getenv('BIDS_EXAMPLES') |
17 | | - if not ret: |
18 | | - examples = load_data('bids-examples') |
19 | | - if not any(examples.iterdir()): |
20 | | - pytest.skip('bids-examples submodule is not checked out') |
21 | | - return examples |
22 | | - return Path(ret) |
| 30 | + return get_submod_or_env('bids-examples', 'BIDS_EXAMPLES') |
23 | 31 |
|
24 | 32 |
|
25 | 33 | @pytest.fixture(scope='session') |
26 | 34 | def gitignore_test() -> Path: |
27 | 35 | """Get bids-examples from submodule, allow environment variable override.""" |
28 | | - ret = os.getenv('GITIGNORE_TEST_DIR') |
29 | | - if not ret: |
30 | | - test_data = load_data('gitignore-test') |
31 | | - if not any(test_data.iterdir()): |
32 | | - pytest.skip('gitignore-test submodule is not checked out') |
33 | | - return test_data |
34 | | - return Path(ret) |
| 36 | + return get_submod_or_env('gitignore-test', 'GITIGNORE_TEST_DIR') |
| 37 | + |
| 38 | + |
| 39 | +@pytest.fixture(scope='session') |
| 40 | +def mrs_data() -> Path: |
| 41 | + """Get MRS data from submodule, allow environment variable override.""" |
| 42 | + mrs_nifti_standard = get_submod_or_env('mrs_nifti_standard', 'MRS_NIFTI_STANDARD') |
| 43 | + return mrs_nifti_standard / 'example_data' / 'examples' |
35 | 44 |
|
36 | 45 |
|
37 | 46 | @pytest.fixture(scope='session') |
|
0 commit comments