-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_m30.py
122 lines (106 loc) · 3.73 KB
/
test_m30.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for the 'MD-EAM' metric (m30).
"""
# ----------------------------------------------------------------------------
# Imports
# ----------------------------------------------------------------------------
# Standard library modules
import pathlib
from typing import Any, List, Optional, Union
# Third-party modules
import pytest
# First-party modules
from aim.common import image_utils
from aim.metrics.m30.m30_mdeam import Metric
from tests.common.constants import DATA_TESTS_INPUT_VALUES_DIR, IDIFF_TOLERANCE
from tests.common.utils import load_expected_result
# ----------------------------------------------------------------------------
# Metadata
# ----------------------------------------------------------------------------
__author__ = "Markku Laine, Yao Wang"
__date__ = "2023-06-08"
__email__ = "[email protected]"
__version__ = "1.0"
# ----------------------------------------------------------------------------
# Tests
# ----------------------------------------------------------------------------
@pytest.mark.parametrize(
["input_value", "expected_results"],
[
(
"aalto.fi_website.png",
[
load_expected_result("m30_0_aalto.fi_website.png"),
load_expected_result("m30_1_aalto.fi_website.png"),
load_expected_result("m30_2_aalto.fi_website.png"),
load_expected_result("m30_3_aalto.fi_website.png"),
load_expected_result("m30_4_aalto.fi_website.png"),
load_expected_result("m30_5_aalto.fi_website.png"),
],
),
(
"myhelsinki.fi_website.png",
[
load_expected_result("m30_0_myhelsinki.fi_website.png"),
load_expected_result("m30_1_myhelsinki.fi_website.png"),
load_expected_result("m30_2_myhelsinki.fi_website.png"),
load_expected_result("m30_3_myhelsinki.fi_website.png"),
load_expected_result("m30_4_myhelsinki.fi_website.png"),
load_expected_result("m30_5_myhelsinki.fi_website.png"),
],
),
],
)
def test_mdeam_desktop(input_value: str, expected_results: List[Any]) -> None:
"""
Test MD-EAM (desktop GUIs).
Args:
input_value: GUI image file name
expected_results: Expected results (list of measures)
"""
# Build GUI image file path
gui_image_filepath: pathlib.Path = (
pathlib.Path(DATA_TESTS_INPUT_VALUES_DIR) / input_value
)
# Read GUI image (PNG)
gui_image_png_base64: str = image_utils.read_image(gui_image_filepath)
# Execute metric
result: Optional[List[Union[int, float, str]]] = Metric.execute_metric(
gui_image_png_base64
)
# Test result
if (
result is not None
and isinstance(result[0], str)
and isinstance(result[1], str)
and isinstance(result[2], str)
and isinstance(result[3], str)
and isinstance(result[4], str)
and isinstance(result[5], str)
):
assert (
image_utils.idiff(result[0], expected_results[0])
<= IDIFF_TOLERANCE
)
assert (
image_utils.idiff(result[1], expected_results[1])
<= IDIFF_TOLERANCE
)
assert (
image_utils.idiff(result[2], expected_results[2])
<= IDIFF_TOLERANCE
)
assert (
image_utils.idiff(result[3], expected_results[3])
<= IDIFF_TOLERANCE
)
assert (
image_utils.idiff(result[4], expected_results[4])
<= IDIFF_TOLERANCE
)
assert (
image_utils.idiff(result[5], expected_results[5])
<= IDIFF_TOLERANCE
)