Skip to content

Commit 09f7d54

Browse files
tests: verify figure using approval testing
Use ImageReporter to verify result figures by displaying an received and approved images of the figure in a diff tool
1 parent 8de5777 commit 09f7d54

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tests/integrationtests/indicators/test_mapping_saturation.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
import numpy as np
55
import plotly.graph_objects as pgo
6-
import plotly.io as pio
76
import pytest
8-
from approvaltests import Options, verify
7+
from approvaltests import Options, verify, verify_binary
98

109
from ohsome_quality_api.indicators.mapping_saturation.indicator import (
1110
MappingSaturation,
1211
)
1312
from tests.approvaltests_namers import PytestNamer
13+
from tests.approvaltests_reporters import ImageDiffReporter
1414
from tests.integrationtests.utils import oqapi_vcr
1515

1616

@@ -113,15 +113,17 @@ def indicator(self, topic_building_count, feature_germany_heidelberg):
113113
i.calculate()
114114
return i
115115

116-
@pytest.mark.skip(reason="Only for manual testing.") # comment for manual test
117-
def test_create_figure_manual(self, indicator):
118-
indicator.create_figure()
119-
pio.show(indicator.result.figure)
120-
121116
def test_create_figure(self, indicator):
122117
indicator.create_figure()
123118
assert isinstance(indicator.result.figure, dict)
124-
pgo.Figure(indicator.result.figure) # test for valid Plotly figure
119+
figure = pgo.Figure(indicator.result.figure).to_image(format="png")
120+
verify_binary(
121+
figure,
122+
".png",
123+
options=Options()
124+
.with_reporter(ImageDiffReporter())
125+
.with_namer(PytestNamer()),
126+
)
125127

126128

127129
@oqapi_vcr.use_cassette

0 commit comments

Comments
 (0)