Skip to content

Commit

Permalink
Add smoke test for QgsHighlight
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 8, 2017
1 parent dc7ec1e commit 05868c2
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ ADD_PYTHON_TEST(PyQgsGeometryGeneratorSymbolLayer test_qgsgeometrygeneratorsymbo
ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
ADD_PYTHON_TEST(PyQgsGeometryValidator test_qgsgeometryvalidator.py)
ADD_PYTHON_TEST(PyQgsGraduatedSymbolRenderer test_qgsgraduatedsymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsHighlight test_qgshighlight.py)
ADD_PYTHON_TEST(PyQgsInterval test_qgsinterval.py)
ADD_PYTHON_TEST(PyQgsJsonUtils test_qgsjsonutils.py)
ADD_PYTHON_TEST(PyQgsLayerMetadata test_qgslayermetadata.py)
Expand Down
99 changes: 99 additions & 0 deletions tests/src/python/test_qgshighlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsHighlight.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Matthias Kuhn'
__date__ = '8.11.2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA
import os

from qgis.PyQt.QtCore import (
QSize,
Qt
)
from qgis.PyQt.QtGui import (
QColor,
QImage,
QPainter
)
from qgis.core import (
QgsVectorLayer,
QgsProject,
QgsRectangle,
QgsMultiRenderChecker
)
from qgis.gui import QgsHighlight
from qgis.testing import start_app, unittest
from qgis.testing.mocked import get_iface
from utilities import unitTestDataPath

start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsHighlight(unittest.TestCase):

def setUp(self):
self.iface = get_iface()

lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr')
QgsProject.instance().addMapLayer(self.lines_layer)
polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
self.polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr')
QgsProject.instance().addMapLayer(self.polys_layer)

self.iface.mapCanvas().resize(QSize(400, 400))

self.iface.mapCanvas().setExtent(QgsRectangle(-113, 28, -91, 40))

self.mapsettings = self.iface.mapCanvas().mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-113, 28, -91, 40))
self.mapsettings.setBackgroundColor(QColor("white"))

def tearDown(self):
QgsProject.instance().removeAllMapLayers()

def testLine(self):
line = next(self.lines_layer.getFeatures()).geometry()
highlight = QgsHighlight(self.iface.mapCanvas(), line, self.lines_layer)
color = QColor(Qt.red)
highlight.setColor(color)
color.setAlpha(50)
highlight.setFillColor(color)
highlight.show()
image = QImage(QSize(400, 400), QImage.Format_ARGB32)
painter = QPainter()
painter.begin(image)
self.iface.mapCanvas().render(painter)
painter.end()

def testPolygon(self):
poly = next(self.polys_layer.getFeatures()).geometry()
self.iface.mapCanvas().setExtent(self.polys_layer.extent())
highlight = QgsHighlight(self.iface.mapCanvas(), poly, self.polys_layer)
color = QColor(Qt.red)
highlight.setColor(color)
color.setAlpha(50)
highlight.setFillColor(color)
highlight.show()
image = QImage(QSize(400, 400), QImage.Format_ARGB32)
painter = QPainter()
painter.begin(image)
self.iface.mapCanvas().render(painter)
painter.end()



if __name__ == '__main__':
unittest.main()

0 comments on commit 05868c2

Please sign in to comment.