-
Notifications
You must be signed in to change notification settings - Fork 43
/
conftest.py
98 lines (79 loc) · 2.61 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
from pathlib import Path
import pytest
PROJ_ROOT = Path(__file__).parents[1]
SCRIPTS_PATH = PROJ_ROOT / "scripts"
TABLES_PATH = PROJ_ROOT / "tables"
IMAGES_PATH = PROJ_ROOT / "images"
FIGURES_PATH = PROJ_ROOT / "figures"
EXAMPLES_PATH = PROJ_ROOT / "examples"
NOTEBOOKS_PATH = PROJ_ROOT / ".doc" / "_notebooks"
EXCLUDE = []
@pytest.fixture(scope="session")
def write(request) -> bool:
return not request.config.getoption("--no-write")
@pytest.fixture(scope="session")
def run(request) -> bool:
return not (
request.config.getoption("--init") or request.config.getoption("--no-run")
)
@pytest.fixture(scope="session")
def plot(request) -> bool:
return request.config.getoption("--plot")
@pytest.fixture(scope="session")
def plot_show(request, plot) -> bool:
return plot and request.config.getoption("--show")
@pytest.fixture(scope="session")
def plot_save(request, plot) -> bool:
return plot and not request.config.getoption("--no-save")
@pytest.fixture(scope="session")
def gif(request, plot) -> bool:
return plot and not request.config.getoption("--no-gif")
def pytest_addoption(parser):
parser.addoption(
"--init",
action="store_true",
default=False,
help="Just build and write model input files",
)
parser.addoption(
"--no-write",
action="store_true",
default=False,
help="Disable model build/write",
)
parser.addoption(
"--no-run", action="store_true", default=False, help="Disable model runs"
)
parser.addoption(
"--plot",
action="store_true",
default=False,
help="Create plots (disabled by default)",
)
parser.addoption(
"--show",
action="store_true",
default=False,
help="Show plots (disabled by default)",
)
parser.addoption(
"--no-save", action="store_true", default=False, help="Disable plot saving"
)
parser.addoption(
"--no-gif", action="store_true", default=False, help="Disable GIF creation"
)
def pytest_generate_tests(metafunc):
# make directories if needed
TABLES_PATH.mkdir(exist_ok=True)
IMAGES_PATH.mkdir(exist_ok=True)
FIGURES_PATH.mkdir(exist_ok=True)
EXAMPLES_PATH.mkdir(exist_ok=True)
NOTEBOOKS_PATH.mkdir(exist_ok=True, parents=True)
# generate example scenarios
if "example_script" in metafunc.fixturenames:
scripts = {
file.name: file
for file in sorted(SCRIPTS_PATH.glob("ex-*.py"))
if file.stem not in EXCLUDE
}
metafunc.parametrize("example_script", scripts.values(), ids=scripts.keys())