Skip to content

Commit 59d4c06

Browse files
committed
test: allow for another output in test_flowchart
1 parent a13fc93 commit 59d4c06

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

eds_scikit/biology/utils/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import glob
2+
import os
23
from pathlib import Path
34
from typing import List
45

56
import pandas as pd
6-
from importlib_metadata import os
77
from loguru import logger
88

99
from eds_scikit.biology.utils.process_concepts import ConceptsSet

eds_scikit/utils/test_utils.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def assert_equal(
9696
return output
9797

9898

99-
def assert_images_equal(image_1: str, image_2: str):
99+
def image_diff(image_1: str, image_2: str):
100100
img1 = Image.open(image_1)
101101
img2 = Image.open(image_2)
102102

@@ -105,12 +105,11 @@ def assert_images_equal(image_1: str, image_2: str):
105105
img2 = img2.resize(img1.size)
106106

107107
sum_sq_diff = np.sum(
108-
(np.asarray(img1).astype("float") - np.asarray(img2).astype("float")) ** 2
109-
)
110-
111-
if sum_sq_diff == 0:
112-
# Images are exactly the same
113-
pass
114-
else:
115-
normalized_sum_sq_diff = sum_sq_diff / np.sqrt(sum_sq_diff)
116-
assert normalized_sum_sq_diff < 0.001
108+
(
109+
np.asarray(img1).astype("float") / 255
110+
- np.asarray(img2).astype("float") / 255
111+
)
112+
** 2
113+
) / np.prod(img1.size)
114+
115+
return sum_sq_diff
20.3 KB
Loading

tests/flowchart/test_flowchart.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from eds_scikit.utils.flowchart import Flowchart
8-
from eds_scikit.utils.test_utils import assert_images_equal
8+
from eds_scikit.utils.test_utils import image_diff
99

1010
data_as_df = pd.DataFrame(
1111
dict(
@@ -63,12 +63,13 @@ def test_flowchart(data, tmpdir_factory):
6363

6464
_ = F.generate_flowchart(alternate=True, fontsize=10)
6565

66-
result_path = tmp_dir / "flowchart.png"
67-
F.save(result_path, dpi=72)
66+
out_path = str(tmp_dir / "flowchart.png")
67+
F.save(out_path, dpi=72)
6868

69-
expected = Path(__file__).parent / "expected_flowchart.png"
69+
tgt_1 = str(Path(__file__).parent / "expected_flowchart.png")
70+
tgt_2 = str(Path(__file__).parent / "expected_flowchart_bis.png")
7071

71-
assert_images_equal(result_path, expected)
72+
assert image_diff(out_path, tgt_1) < 0.05 or image_diff(out_path, tgt_2) < 0.05
7273

7374

7475
def test_incorrect_data():

0 commit comments

Comments
 (0)