-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtests.py
More file actions
42 lines (34 loc) · 1.51 KB
/
tests.py
File metadata and controls
42 lines (34 loc) · 1.51 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
from pathlib import Path
import numpy as np
import pytest
from pytest_lazy_fixtures import lf
from tasks.utils import initialize, parametrize_invocation
from toolarena.run import ToolRunResult
initialize()
@parametrize_invocation("kather100k_muc", "tcga_brca_patch_png", "tcga_brca_patch_jpg")
def test_status(invocation: ToolRunResult):
assert invocation.status == "success"
@parametrize_invocation("kather100k_muc", "tcga_brca_patch_png", "tcga_brca_patch_jpg")
def test_shape_and_type(invocation: ToolRunResult):
assert "features" in invocation.result
features = invocation.result["features"]
assert isinstance(features, list)
assert len(features) == 1024
assert all(isinstance(feature, float) for feature in features)
@pytest.mark.parametrize(
"invocation,expected_features_file",
[
(lf(test_case), Path(__file__).parent.joinpath("data", "tests", filename))
for (test_case, filename) in {
"kather100k_muc": "uni_MUC-TCGA-ACCPKIPN.tif.npy",
"tcga_brca_patch_png": "uni_TCGA-BRCA_patch_TCGA-BH-A0DE-01Z-00-DX1.64A0340A-8146-48E8-AAF7-4035988B9152.png.npy",
"tcga_brca_patch_jpg": "uni_TCGA-BRCA_patch_TCGA-BH-A0DE-01Z-00-DX1.64A0340A-8146-48E8-AAF7-4035988B9152.jpg.npy",
}.items()
],
)
def test_feature_values(invocation: ToolRunResult, expected_features_file: Path):
np.testing.assert_allclose(
np.array(invocation.result["features"], dtype=np.float32),
np.load(expected_features_file).squeeze(),
atol=1e-3,
)