-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_executable.py
More file actions
62 lines (47 loc) · 1.8 KB
/
test_executable.py
File metadata and controls
62 lines (47 loc) · 1.8 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
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
_BINARIES_FILE = Path(__file__).parent.parent / "binaries.txt"
_EXPECTED_TOOLS = sorted(
line.strip() for line in _BINARIES_FILE.read_text().splitlines() if line.strip()
)
all_tools = pytest.mark.parametrize("tool", _EXPECTED_TOOLS)
all_tools_version = pytest.mark.parametrize(
("tool", "expected_version"),
[(t, "1.0") for t in _EXPECTED_TOOLS],
)
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