Skip to content
Permalink
Browse files
[test] Fix canvas size and background garbage
  • Loading branch information
m-kuhn committed Nov 8, 2017
1 parent 593bff2 commit 42c9d158cf4044fb82fe73d3ee0072a3ea7ed1b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
@@ -24,7 +24,8 @@
from qgis.PyQt.QtGui import (
QColor,
QImage,
QPainter
QPainter,
QResizeEvent
)
from qgis.core import (
QgsVectorLayer,
@@ -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()
@@ -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)
@@ -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):
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.