forked from imagej/pyimagej
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
48 lines (40 loc) · 1.25 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
import imagej
import pytest
import argparse
def pytest_addoption(parser):
"""
Set up the command line parser for IJ location and headless mode
:param parser: pytest's parser, passed in automatically
:return: None
"""
parser.addoption(
"--ij", action="store", default=None, help="directory to IJ"
)
parser.addoption(
"--headless", type=str2bool, action="store", default=True, help="Start in headless mode"
)
@pytest.fixture(scope='session')
def ij_fixture(request):
"""
Create an ImageJ instance to be used by the whole testing environment
:param request: Pytest variable passed in to fixtures
:return: pyimageJ instance
"""
ij_dir = request.config.getoption('--ij')
headless = request.config.getoption('--headless')
ij_wrapper = imagej.init(ij_dir, headless=headless)
return ij_wrapper
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')