Skip to content

Commit eac65cb

Browse files
Thomas Carrollsnus-kin
authored andcommitted
refactor: use TypedDict
1 parent a43d4b6 commit eac65cb

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

tests/functional/e2e/testcases/parser.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import json
22
from pathlib import Path
3-
from typing import cast
3+
from typing import TypedDict, cast
44

55
# Path to the shared testcases directory in athena-protobufs
66
_REPO_ROOT = Path(__file__).parent.parent.parent.parent.parent
77
TESTCASES_DIR = _REPO_ROOT / "athena-protobufs" / "testcases"
88

99

10+
class TestCases(TypedDict):
11+
classification_labels: list[str]
12+
images: list[list[str | list[float]]]
13+
14+
1015
class AthenaTestCase:
1116
def __init__(
1217
self,
@@ -28,13 +33,9 @@ def load_test_cases(dirname: str = "benign_model") -> list[AthenaTestCase]:
2833
with Path.open(
2934
Path(TESTCASES_DIR / dirname / "expected_outputs.json"),
3035
) as f:
31-
test_cases = cast(
32-
"dict[str, list[str] | list[list[str | list[float]]]]", json.load(f)
33-
)
34-
classification_labels = cast(
35-
"list[str]", test_cases["classification_labels"]
36-
)
37-
images = cast("list[list[str | list[float]]]", test_cases["images"])
36+
test_cases: TestCases = cast("TestCases", json.load(f))
37+
classification_labels = test_cases["classification_labels"]
38+
images = test_cases["images"]
3839
return [
3940
AthenaTestCase(
4041
str(

0 commit comments

Comments
 (0)