Class: QgsMultiRenderChecker

class qgis.core.QgsMultiRenderChecker

Bases: sip.wrapper

This class allows checking rendered images against comparison images.

Its main purpose is for the unit testing framework.

It will either <ul> <li>take an externally rendered image (setRenderedImage())</li> <li>render the image based on provided mapSettings (setMapSettings())</li> </ul>

This image will then be compared against one or several images in a folder inside the control directory (tests/testdata/control_images/{controlName}).

There are modes for single and for multiple reference images. <ul> <li>If there are no subfolders in the control directory, it will assume an image with the name {controlImage}.png in the control directory itself.</li>

<li>If there are subfolders inside the control directory, it will search for images with the name {controlImage}.png in every subfolder.</li> </ul>

For every control image there may be one or several randomly named anomaly images defining allowed anomalies. For every control image, the allowed mismatch and color tolerance values will be calculated individually.

QgsMultiRenderChecker() Constructor for QgsMultiRenderChecker.

QgsMultiRenderChecker(QgsMultiRenderChecker)

Methods

controlImagePath

Returns the path to the control images.

drawBackground

Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image

markdownReport

Returns a markdown report for this test.

report

Returns a HTML report for this test.

runTest

Test using renderer to generate the image to be compared.

setColorTolerance

Set tolerance for color components used by runTest() Default value is 0.

setControlName

Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + '/' + mControlName + '/' + mControlName + '.png'

setControlPathPrefix

Sets the path prefix where the control images are kept.

setExpectFail

Sets whether the comparison is expected to fail.

setFileFunctionLine

Sets the source file, function and line from where the test originates.

setMapSettings

Set the map settings to use to render the image

setRenderedImage

Set the path to the rendered image.

setSizeTolerance

Sets the largest allowable difference in size between the rendered and the expected image.

controlImagePath(self) str

Returns the path to the control images.

Return type:

str

drawBackground(image: QImage)

Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image

Parameters:

image (QImage) –

markdownReport(self) str

Returns a markdown report for this test.

The report will be empty if the test was successfully run.

See also

report()

New in version 3.34.

Return type:

str

report(self) str

Returns a HTML report for this test.

The report will be empty if the test was successfully run.

See also

markdownReport()

Return type:

str

runTest(self, testName: str, mismatchCount: int = 0) bool

Test using renderer to generate the image to be compared.

Parameters:
  • testName (str) –

    • to be used as the basis for writing a file to

    e.g. /tmp/theTestName.png

  • mismatchCount (int = 0) –

    • defaults to 0 - the number of pixels that

    are allowed to be different from the control image. In some cases rendering may be non-deterministic. This parameter allows you to account for that by providing a tolerance.

Note

make sure to call setExpectedImage and setMapSettings first

Return type:

bool

setColorTolerance(self, colorTolerance: int)

Set tolerance for color components used by runTest() Default value is 0.

Parameters:

colorTolerance (int) – The maximum difference for each color component including alpha to be considered correct.

setControlName(self, name: str)

Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + ‘/’ + mControlName + ‘/’ + mControlName + ‘.png’

Parameters:

name (str) –

setControlPathPrefix(self, prefix: str)

Sets the path prefix where the control images are kept.

Parameters:

prefix (str) –

setExpectFail(self, expectFail: bool)

Sets whether the comparison is expected to fail.

New in version 3.28.

Parameters:

expectFail (bool) –

setFileFunctionLine(self, file: str, function: str, line: int)

Sets the source file, function and line from where the test originates.

New in version 3.36.

Parameters:
  • file (str) –

  • function (str) –

  • line (int) –

setMapSettings(self, mapSettings: QgsMapSettings)

Set the map settings to use to render the image

Parameters:

mapSettings (QgsMapSettings) – The map settings

setRenderedImage(self, renderedImagePath: str)

Set the path to the rendered image. If this is not set or set to null QString, an image will be rendered based on the provided mapsettings

Parameters:

renderedImagePath (str) – A path to the rendered image with which control images will be compared

setSizeTolerance(self, xTolerance: int, yTolerance: int)

Sets the largest allowable difference in size between the rendered and the expected image.

Parameters:
  • xTolerance (int) – x tolerance in pixels

  • yTolerance (int) – y tolerance in pixels