Skip to content

Commit

Permalink
update test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Nov 10, 2024
1 parent b70dd27 commit bba2313
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
20 changes: 12 additions & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import tempfile
from typing import Union
import pytest

from qgis.core import (QgsReadWriteContext, QgsTextFormat)

from qgis.PyQt.QtXml import QDomElement, QDomDocument

from PIL import Image

import numpy as np
import pytest
from PIL import Image
from pixelmatch.contrib.PIL import pixelmatch
from qgis.core import QgsReadWriteContext, QgsTextFormat
from qgis.PyQt.QtXml import QDomDocument, QDomElement

from BivariateRenderer.renderer.bivariate_renderer import BivariateRenderer

Expand Down Expand Up @@ -55,8 +54,13 @@ def assert_images_equal(image_1: str, image_2: str):
normalized_sum_sq_diff = 0

if normalized_sum_sq_diff > 0.001:
diff_mask = Image.new("RGBA", img1.size)
pixelmatch(img1, img2, diff_mask, includeAA=True)
filename = tempfile.gettempdir() + '/diff_mask.png'
diff_mask.save(filename)

__tracebackhide__ = True
pytest.fail(f"Images \n{image_1}\n{image_2}\ndo not look the same.\n"
f"Difference is {normalized_sum_sq_diff}.")
f"Difference is {normalized_sum_sq_diff}. Diff file {filename}.")
else:
pass
18 changes: 5 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,18 @@ def layout_page_a4(qgs_layout: QgsLayout, layout_dpmm, layout_height, layout_wid
def prepare_bivariate_renderer():

def return_bivariate_renderer(
layer: QgsVectorLayer, field1: str = "", field2: str = "", color_ramps: Optional[BivariateColorRamp] = None
layer: QgsVectorLayer, field1: str = "", field2: str = "", color_ramp: Optional[BivariateColorRamp] = None
) -> BivariateRenderer:

if color_ramps is None:
color_ramp_bivariate = BivariateColorRampsRegister().get_by_name("Violet - Blue")

color_ramp = BivariateColorRampsRegister().get_by_name("Violet - Blue")

default_color_ramp_1 = color_ramp.color_ramp_1
default_color_ramp_2 = color_ramp.color_ramp_2

else:

default_color_ramp_1 = color_ramps.color_ramp_1
default_color_ramp_2 = color_ramps.color_ramp_2
if color_ramp:
color_ramp_bivariate = color_ramp

bivariate_renderer = BivariateRenderer()
bivariate_renderer.setFieldName1(field1)
bivariate_renderer.setFieldName2(field2)
bivariate_renderer.setColorRamp1(default_color_ramp_1)
bivariate_renderer.setColorRamp2(default_color_ramp_2)
bivariate_renderer.set_bivariate_color_ramp(color_ramp_bivariate)
bivariate_renderer.setField1ClassificationData(layer, bivariate_renderer.field_name_1)
bivariate_renderer.setField2ClassificationData(layer, bivariate_renderer.field_name_2)

Expand Down

0 comments on commit bba2313

Please sign in to comment.