Skip to content

Commit

Permalink
[test] Fix canvas size and background garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 8, 2017
1 parent 593bff2 commit 42c9d15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/src/python/test_qgshighlight.py
Expand Up @@ -24,7 +24,8 @@
from qgis.PyQt.QtGui import (
QColor,
QImage,
QPainter
QPainter,
QResizeEvent
)
from qgis.core import (
QgsVectorLayer,
Expand All @@ -46,7 +47,9 @@ class TestQgsHighlight(unittest.TestCase):
def setUp(self):
self.iface = get_iface()

self.iface.mapCanvas().resize(QSize(400, 400))
self.iface.mapCanvas().viewport().resize(400, 400)
# For some reason the resizeEvent is not delivered, fake it
self.iface.mapCanvas().resizeEvent(QResizeEvent(QSize(400, 400), self.iface.mapCanvas().size()))

def tearDown(self):
QgsProject.instance().removeAllMapLayers()
Expand All @@ -63,11 +66,13 @@ def runTestForLayer(self, layer, testname):
highlight = QgsHighlight(self.iface.mapCanvas(), geom, layer)
color = QColor(Qt.red)
highlight.setColor(color)
highlight.setWidth(1)
color.setAlpha(50)
highlight.setFillColor(color)
highlight.show()

image = QImage(QSize(400, 400), QImage.Format_ARGB32)
image.fill(Qt.white)
painter = QPainter()
painter.begin(image)
self.iface.mapCanvas().render(painter)
Expand All @@ -78,8 +83,7 @@ def runTestForLayer(self, layer, testname):
checker.setControlPathPrefix("highlight")
checker.setControlName("expected_highlight_{}".format(testname))
checker.setRenderedImage(control_image)
checker.setSizeTolerance(10, 10)
self.assertTrue(checker.compareImages("highlight_{}".format(testname), 10))
self.assertTrue(checker.compareImages("highlight_{}".format(testname)))
shutil.rmtree(tempdir)

def testLine(self):
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 42c9d15

Please sign in to comment.