Skip to content

Commit

Permalink
Fix test in ARM docker container by allowing high leeway for some pix…
Browse files Browse the repository at this point in the history
…els, and allow small difference in the color palette.
  • Loading branch information
lukas-phaf committed Jun 29, 2023
1 parent 0562239 commit 953578a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
26 changes: 25 additions & 1 deletion python/lib/adaguc/AdagucTestTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def compareImage(
returnedImagePath,
maxAllowedColorDifference=1,
maxAllowedColorPercentage=0.01,
maxAllowedPaletteDifference=1
):
"""Compare the pictures referred to by the arguments.
Expand All @@ -158,6 +159,7 @@ def compareImage(
returnedImagePath (str): path of the image that we got as output from the test
maxAllowedColorDifference(int): max allowed difference in a single color band
maxAllowedColorPercentage(float): max allowed percentage of pixels that have different colors
maxAllowedPaletteDifference(int): max allowed difference in the color palette
Returns:
bool: True if the difference is "small enough"
Expand All @@ -170,6 +172,28 @@ def compareImage(
)
return False

if expected_image.mode != returned_image.mode:
print(
f"\nError, mode of expected and actual image do not match: {expected_image.mode} vs {returned_image.mode}"
)
return False
if returned_image.mode == "P":
expected_palette = expected_image.getpalette()
returned_palette = returned_image.getpalette()
if expected_palette != returned_palette:
if len(expected_palette) != len(returned_palette):
print("Error, palette length don't match!!")
return False
max_pallete_difference_exceeded = False
for i in range(0, len(expected_palette)):
if expected_palette[i] != returned_palette[i]:
if abs(expected_palette[i] - returned_palette[i]) > maxAllowedPaletteDifference:
max_pallete_difference_exceeded = True
print(f"Palette difference: {i}: {expected_palette[i]}, {returned_palette[i]}")
if max_pallete_difference_exceeded:
print(f"Error, max palette difference ({maxAllowedPaletteDifference}) exceeded.")
return False

width, height = expected_image.size
n_bands = len(expected_image.getbands())

Expand Down Expand Up @@ -213,7 +237,7 @@ def compareImage(

if max_color_difference_value > maxAllowedColorDifference:
print(
f"Error, difference for pixel {c} is too large ({max_color_difference_value} > {maxAllowedColorDifference})",
f"Error, difference for pixel {max_color_difference_pixel} is too large ({max_color_difference_value} > {maxAllowedColorDifference})",
flush=True,
)
return False
Expand Down
15 changes: 7 additions & 8 deletions tests/AdagucTests/TestWMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,9 @@ def test_WMSGetMapWithShowLegendSecondLayer_testdatanc(self):
AdagucTestTools().writetofile(self.testresultspath + filename,
data.getvalue())
self.assertEqual(status, 0)
self.assertEqual(
data.getvalue(),
AdagucTestTools().readfromfile(self.expectedoutputsspath +
filename))
self.assertTrue(AdagucTestTools().compareImage(
self.expectedoutputsspath + filename,
self.testresultspath + filename))

def test_WMSGetMapWithShowLegendAllLayers_testdatanc(self):
AdagucTestTools().cleanTempDir()
Expand Down Expand Up @@ -1848,7 +1847,7 @@ def test_WMSGetMap_dashed_contour_lines(self):
AdagucTestTools().writetofile(self.testresultspath + filename,
data.getvalue())
self.assertEqual(status, 0)
self.assertEqual(
data.getvalue(),
AdagucTestTools().readfromfile(self.expectedoutputsspath +
filename))
self.assertTrue(AdagucTestTools().compareImage(
self.expectedoutputsspath + filename,
self.testresultspath + filename,
64, 0.001)) # Allowed pixel difference is huge, but only for very small number of pixels

0 comments on commit 953578a

Please sign in to comment.