Skip to content

Commit 7b60bb8

Browse files
committed
test: allow for another output in test_flowchart
1 parent d72662d commit 7b60bb8

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## Unreleased
44

5-
### Changed
5+
### Added
66

77
- Support for pyarrow > 0.17.0
8+
- Support for Python 3.7 to 3.10 (3.11 or higher is not tested)
89
- Support for pyspark 3 (to force pyspark 2, use `pip install eds-scikit[spark2]`)
910

1011
### Fixed

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 images_are_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 images_are_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-
return True
114-
else:
115-
normalized_sum_sq_diff = sum_sq_diff / np.sqrt(sum_sq_diff)
116-
return 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

tests/flowchart/test_flowchart.py

Lines changed: 5 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 images_are_equal
8+
from eds_scikit.utils.test_utils import image_diff
99

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

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

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

69-
target_1 = Path(__file__).parent / "expected_flowchart.png"
70-
target_2 = Path(__file__).parent / "expected_flowchart_bis.png"
69+
tgt_1 = str(Path(__file__).parent / "expected_flowchart.png")
70+
tgt_2 = str(Path(__file__).parent / "expected_flowchart_bis.png")
7171

72-
assert images_are_equal(out_path, target_1) or images_are_equal(out_path, target_2)
72+
assert image_diff(out_path, tgt_1) < 0.05 or image_diff(out_path, tgt_2) < 0.05
7373

7474

7575
def test_incorrect_data():

0 commit comments

Comments
 (0)