-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_executable.py
More file actions
74 lines (60 loc) · 1.97 KB
/
test_executable.py
File metadata and controls
74 lines (60 loc) · 1.97 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
from __future__ import annotations
import subprocess
import sysconfig
from importlib.metadata import distribution
from pathlib import Path
import pytest
import dcmqi
from . import push_argv
all_tools = pytest.mark.parametrize(
"tool",
[
"itkimage2segimage",
"segimage2itkimage",
"tid1500writer",
"tid1500reader",
"itkimage2paramap",
"paramap2itkimage",
],
)
all_tools_version = pytest.mark.parametrize(
("tool", "expected_version"),
[
("itkimage2segimage", "1.0"),
("segimage2itkimage", "1.0"),
("tid1500writer", "1.0"),
("tid1500reader", "1.0"),
("itkimage2paramap", "1.0"),
("paramap2itkimage", "1.0"),
],
)
def _get_scripts():
dist = distribution("dcmqi")
scripts_paths = [
Path(sysconfig.get_path("scripts", scheme)).resolve()
for scheme in sysconfig.get_scheme_names()
]
scripts = []
for file in dist.files:
if file.locate().parent.resolve(strict=True) in scripts_paths:
scripts.append(file.locate().resolve(strict=True))
return scripts
@all_tools_version
def test_package_script(tool, expected_version):
"""
Example of the output for tid1500writer (analogous for the other tools):
tid1500writer --version
dcmqi repository URL: https://github.com/QIICR/dcmqi revision: 1922a09 tag: v1.3.1
/home/leonard/miniconda3/envs/dcmqi_pypi_test/lib/python3.8/site-packages/dcmqi/bin/tid1500writer version: 1.0
"""
scripts = [script for script in _get_scripts() if script.stem == tool]
assert len(scripts) == 1
output = subprocess.check_output([str(scripts[0]), "--version"]).decode("ascii")
assert output.splitlines()[2].split(" ")[1] == f"version: {expected_version}"
@all_tools
def test_module(tool):
func = getattr(dcmqi, tool)
args = [f"{tool}.py", "--version"]
with push_argv(args), pytest.raises(SystemExit) as excinfo:
func()
assert excinfo.value.code == 0