-
Notifications
You must be signed in to change notification settings - Fork 23
/
conftest.py
110 lines (87 loc) · 2.94 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <nipreps@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""py.test configuration."""
import os
from pathlib import Path
import numpy
import nibabel
import pytest
from bids.layout import BIDSLayout
# disable ET
os.environ['NO_ET'] = '1'
test_data_env = os.getenv("TEST_DATA_HOME", str(Path.home() / "sdcflows-tests"))
test_output_dir = os.getenv("TEST_OUTPUT_DIR")
test_workdir = os.getenv("TEST_WORK_DIR")
_sloppy_mode = os.getenv("TEST_PRODUCTION", "off").lower() not in ("on", "1", "true", "yes", "y")
layouts = {
p.name: BIDSLayout(str(p), validate=False, derivatives=True)
for p in Path(test_data_env).glob("*")
if p.is_dir()
}
data_dir = Path(__file__).parent / "tests" / "data"
layouts.update({
folder.name: BIDSLayout(folder, validate=False, derivatives=False)
for folder in data_dir.glob("ds*") if folder.is_dir()
})
def pytest_report_header(config):
return f"""\
TEST_DATA_HOME={test_data_env}
-> Available datasets: {', '.join(layouts.keys())}.
TEST_OUTPUT_DIR={test_output_dir or '<unset> (output files will be discarded)'}.
TEST_WORK_DIR={test_workdir or '<unset> (intermediate files will be discarded)'}.
"""
@pytest.fixture(autouse=True)
def add_np(doctest_namespace):
doctest_namespace["np"] = numpy
doctest_namespace["nb"] = nibabel
doctest_namespace["os"] = os
doctest_namespace["Path"] = Path
doctest_namespace["layouts"] = layouts
for key, val in list(layouts.items()):
doctest_namespace[key] = Path(val.root)
doctest_namespace["dsA_dir"] = data_dir / "dsA"
doctest_namespace["dsB_dir"] = data_dir / "dsB"
doctest_namespace["dsC_dir"] = data_dir / "dsC"
@pytest.fixture
def workdir():
return None if test_workdir is None else Path(test_workdir)
@pytest.fixture
def outdir():
return None if test_output_dir is None else Path(test_output_dir)
@pytest.fixture
def bids_layouts():
if layouts:
return layouts
pytest.skip()
@pytest.fixture
def datadir():
return Path(test_data_env)
@pytest.fixture
def testdata_dir():
return data_dir
@pytest.fixture
def dsA_dir():
return data_dir / "dsA"
@pytest.fixture
def sloppy_mode():
return _sloppy_mode