-
Notifications
You must be signed in to change notification settings - Fork 83
/
conftest.py
69 lines (57 loc) · 1.64 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
import argparse
import pytest
import imagej
def pytest_addoption(parser):
"""
Set up the command line parser for ImageJ location and headless mode
:param parser: pytest's parser, passed in automatically
:return: None
"""
parser.addoption(
"--ij",
action="store",
default=None,
help="directory or endpoint (see imagej.init)",
)
parser.addoption(
"--headless",
type=str2bool,
action="store",
default=True,
help="Start in headless mode",
)
parser.addoption(
"--legacy",
type=str2bool,
action="store",
default=True,
help="Include the original ImageJ",
)
@pytest.fixture(scope="session")
def ij(request):
"""
Create an ImageJ instance to be used by the whole testing environment
:param request: Pytest variable passed in to fixtures
"""
ij_dir = request.config.getoption("--ij")
legacy = request.config.getoption("--legacy")
headless = request.config.getoption("--headless")
imagej.when_imagej_starts(lambda ij: setattr(ij, "_testing", True))
mode = "headless" if headless else "interactive"
ij = imagej.init(ij_dir, mode=mode, add_legacy=legacy)
yield ij
ij.dispose()
def str2bool(v):
"""
Convert string inputs into bool
:param v: A string
:return: Corresponding boolean
"""
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise argparse.ArgumentTypeError("Boolean value expected")