Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
84 lines (76 loc) · 2.35 KB
/
Copy pathconftest.py
File metadata and controls
84 lines (76 loc) · 2.35 KB
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
import argparse
import subprocess
import pytest
import imagej
import imagej.doctor
from scyjava import config
def pytest_addoption(parser):
"""
Set up the command line parser for ImageJ2 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",
)
parser.addoption(
"--java",
action="store",
default="11",
help="version of Java to cache and use (e.g. 8, 11, 17, 21)",
)
@pytest.fixture(scope="session")
def ij(request):
"""
Create an ImageJ2 gateway to be used by the whole testing environment
:param request: Pytest variable passed in to fixtures
"""
# enable debug logging
imagej.doctor.debug_to_stderr()
# get test configuration
ij_dir = request.config.getoption("--ij")
legacy = request.config.getoption("--legacy")
headless = request.config.getoption("--headless")
java_version = request.config.getoption("--java")
config.set_java_constraints(fetch=True, vendor='zulu', version=java_version)
# JavaScript is used in the tests. But the Nashorn engine was
# dropped from the JDK at v15, so we readd it here if needed.
if int(java_version) >= 15:
config.endpoints.append("org.openjdk.nashorn:nashorn-core")
imagej.when_imagej_starts(lambda ij: setattr(ij, "_java_version", java_version))
# initialize the ImageJ2 gateway
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")