Class: QgsRenderChecker

class qgis.core.QgsRenderChecker

Bases: sip.wrapper

Constructor for QgsRenderChecker.

QgsRenderChecker(QgsRenderChecker)

This is a helper class for unit tests that need to write an image and compare it to an expected result or render time.

Enums

Methods

compareImages

Test using two arbitrary images (map renderer will not be used)

controlImagePath

dartMeasurements

Gets access to buffered dash messages.

drawBackground

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

elapsedTime

enableDashBuffering

Call this to enable internal buffering of dash messages.

expectedImageFile

Returns the path to the expected image file

imageToHash

Gets an md5 hash that uniquely identifies an image

isKnownAnomaly

Gets a list of all the anomalies.

matchPercent

matchTarget

mismatchCount

renderedImage

The path of the rendered image can be retrieved through that method.

report

runTest

Test using renderer to generate the image to be compared.

setColorTolerance

Set tolerance for color components used by runTest() and compareImages().

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

Prefix where the control images are kept.

setControlPathSuffix

setElapsedTimeTarget

setMapSettings

New in version 2.4.

setRenderedImage

setSizeTolerance

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

Signals

Attributes

compareImages(self, testName: str, mismatchCount: int = 0, renderedImageFile: str = '') → bool

Test using two arbitrary images (map renderer will not be used)

Parameters
  • testName

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

    e.g. /tmp/theTestName.png

  • mismatchCount

    • 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.

  • renderedImageFile – to optionally override the output filename

note: make sure to call setExpectedImage and setRenderedImage first.

controlImagePath(self) → str
dartMeasurements(self) → object

Gets access to buffered dash messages. Only will return something if you call enableDashBuffering( True ); before.

Returns

buffered dash messages

drawBackground(image: QImage)

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

elapsedTime(self) → int
enableDashBuffering(self, enable: bool)

Call this to enable internal buffering of dash messages. You may later call dashMessages() to get access to the buffered messages. If disabled (default) dash messages will be sent immediately.

Parameters

enable – Enable or disable buffering

expectedImageFile(self) → str

Returns the path to the expected image file

Returns

Path to the expected image file

imageToHash(self, imageFile: str) → str

Gets an md5 hash that uniquely identifies an image

isKnownAnomaly(self, diffImageFile: str) → bool

Gets a list of all the anomalies. An anomaly is a rendered difference file where there is some red pixel content (indicating a render check mismatch), but where the output was still acceptable. If the render diff matches one of these anomalies we will still consider it to be acceptable.

Returns

a bool indicating if the diff matched one of the anomaly files

matchPercent(self) → float
matchTarget(self) → int
mismatchCount(self) → int
renderedImage(self) → str

The path of the rendered image can be retrieved through that method. Will return the path set with setRenderedImage() or generated in runTest()

Returns

The path to the rendered image

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

Test using renderer to generate the image to be compared.

Parameters
  • testName

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

    e.g. /tmp/theTestName.png

  • mismatchCount

    • 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 setMapRenderer first

setColorTolerance(self, colorTolerance: int)

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

Parameters

colorTolerance – is maximum difference for each color component including alpha to be considered correct.

New in version 2.1.

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’

setControlPathPrefix(self, name: str)

Prefix where the control images are kept. This will be appended to controlImagePath

setControlPathSuffix(self, name: str)
setElapsedTimeTarget(self, target: int)
setMapSettings(self, mapSettings: QgsMapSettings)

New in version 2.4.

setRenderedImage(self, imageFileName: str)
setSizeTolerance(self, xTolerance: int, yTolerance: int)

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

Parameters
  • xTolerance – x tolerance in pixels

  • yTolerance – y tolerance in pixels

New in version 2.12.