-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inspect.py
More file actions
92 lines (77 loc) · 2.36 KB
/
test_inspect.py
File metadata and controls
92 lines (77 loc) · 2.36 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
85
86
87
88
89
90
91
92
import subprocess
import sys
from pathlib import Path
import pytest
from ppadb.client import Client as AdbClient
ROOT = Path(__file__).resolve().parents[1]
MNIST_ROOT = ROOT / "examples" / "mnistwild"
def has_connected_device() -> bool:
client = AdbClient(host="127.0.0.1", port=5037)
return bool(client.devices())
def run_cli(args: list[str], timeout: int = 180) -> None:
subprocess.run(args, check=True, timeout=timeout)
def test_model_inspect_mnist() -> None:
if not has_connected_device():
pytest.skip("No Android device connected")
run_cli(
[
sys.executable,
"-m",
"securemr.inspect.model_cli",
"--model",
str(MNIST_ROOT / "mnist.serialized.bin"),
"--json",
str(MNIST_ROOT / "mnist.serialized.json"),
]
)
def test_pipeline_inspect_mnist() -> None:
if not has_connected_device():
pytest.skip("No Android device connected")
run_cli(
[
sys.executable,
"-m",
"securemr.inspect.pipeline_cli",
"--pipeline",
str(MNIST_ROOT / "mnist_pipeline.json"),
],
timeout=240,
)
def test_pipeline_inspect_mnist_with_input() -> None:
if not has_connected_device():
pytest.skip("No Android device connected")
run_cli(
[
sys.executable,
"-m",
"securemr.inspect.pipeline_cli",
"--pipeline",
str(MNIST_ROOT / "mnist_pipeline.json"),
"--input",
str(MNIST_ROOT / "number_5.png"),
"--input-tensor",
"left_rgb",
],
timeout=240,
)
def test_pipeline_inspect_mnist_with_outputs() -> None:
if not has_connected_device():
pytest.skip("No Android device connected")
run_cli(
[
sys.executable,
"-m",
"securemr.inspect.pipeline_cli",
"--pipeline",
str(MNIST_ROOT / "mnist_pipeline.json"),
"--input",
str(MNIST_ROOT / "number_5.png"),
"--input-tensor",
"left_rgb",
"--output",
str(MNIST_ROOT / "number_5_target_output" / "predicted_class.bin"),
"--output",
str(MNIST_ROOT / "number_5_target_output" / "predicted_score.bin"),
],
timeout=240,
)