Skip to content

Commit 150ddce

Browse files
committed
add test_no_req_measures_for_mode_fixed
1 parent 261ff92 commit 150ddce

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import dataclasses
2+
3+
import pytest
4+
5+
from bioimageio.core.prediction_pipeline._processing import KNOWN_PROCESSING
6+
from bioimageio.core.prediction_pipeline._utils import FIXED
7+
8+
try:
9+
from typing import get_args
10+
except ImportError:
11+
from typing_extensions import get_args # type: ignore
12+
13+
14+
@pytest.mark.parametrize(
15+
"proc",
16+
list(KNOWN_PROCESSING["pre"].values()) + list(KNOWN_PROCESSING["post"].values()),
17+
)
18+
def test_no_req_measures_for_mode_fixed(proc):
19+
# check if mode=fixed is valid for this proc
20+
for f in dataclasses.fields(proc):
21+
if f.name == "mode":
22+
break
23+
else:
24+
raise AttributeError("Processing is missing mode attribute")
25+
# mode is always annotated as literals (or literals of literals)
26+
valid_modes = get_args(f.type)
27+
for inner in get_args(f.type):
28+
valid_modes += get_args(inner)
29+
30+
if FIXED not in valid_modes:
31+
return
32+
33+
# we might be missing required kwargs. These have marshmallow.missing value as default
34+
# and raise a TypeError is in __post_init__()
35+
proc.__post_init__ = lambda self: None # ignore missing kwargs
36+
37+
proc_instance = proc(tensor_name="tensor_name", mode=FIXED)
38+
req_measures = proc_instance.get_required_measures()
39+
assert not req_measures

0 commit comments

Comments
 (0)