Skip to content

Commit 05868c2

Browse files
committedNov 8, 2017
Add smoke test for QgsHighlight
1 parent dc7ec1e commit 05868c2

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ADD_PYTHON_TEST(PyQgsGeometryGeneratorSymbolLayer test_qgsgeometrygeneratorsymbo
7272
ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
7373
ADD_PYTHON_TEST(PyQgsGeometryValidator test_qgsgeometryvalidator.py)
7474
ADD_PYTHON_TEST(PyQgsGraduatedSymbolRenderer test_qgsgraduatedsymbolrenderer.py)
75+
ADD_PYTHON_TEST(PyQgsHighlight test_qgshighlight.py)
7576
ADD_PYTHON_TEST(PyQgsInterval test_qgsinterval.py)
7677
ADD_PYTHON_TEST(PyQgsJsonUtils test_qgsjsonutils.py)
7778
ADD_PYTHON_TEST(PyQgsLayerMetadata test_qgslayermetadata.py)

‎tests/src/python/test_qgshighlight.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsHighlight.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Matthias Kuhn'
10+
__date__ = '8.11.2017'
11+
__copyright__ = 'Copyright 2017, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis # NOQA
16+
import os
17+
18+
from qgis.PyQt.QtCore import (
19+
QSize,
20+
Qt
21+
)
22+
from qgis.PyQt.QtGui import (
23+
QColor,
24+
QImage,
25+
QPainter
26+
)
27+
from qgis.core import (
28+
QgsVectorLayer,
29+
QgsProject,
30+
QgsRectangle,
31+
QgsMultiRenderChecker
32+
)
33+
from qgis.gui import QgsHighlight
34+
from qgis.testing import start_app, unittest
35+
from qgis.testing.mocked import get_iface
36+
from utilities import unitTestDataPath
37+
38+
start_app()
39+
TEST_DATA_DIR = unitTestDataPath()
40+
41+
42+
class TestQgsHighlight(unittest.TestCase):
43+
44+
def setUp(self):
45+
self.iface = get_iface()
46+
47+
lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
48+
self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr')
49+
QgsProject.instance().addMapLayer(self.lines_layer)
50+
polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
51+
self.polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr')
52+
QgsProject.instance().addMapLayer(self.polys_layer)
53+
54+
self.iface.mapCanvas().resize(QSize(400, 400))
55+
56+
self.iface.mapCanvas().setExtent(QgsRectangle(-113, 28, -91, 40))
57+
58+
self.mapsettings = self.iface.mapCanvas().mapSettings()
59+
self.mapsettings.setOutputSize(QSize(400, 400))
60+
self.mapsettings.setOutputDpi(96)
61+
self.mapsettings.setExtent(QgsRectangle(-113, 28, -91, 40))
62+
self.mapsettings.setBackgroundColor(QColor("white"))
63+
64+
def tearDown(self):
65+
QgsProject.instance().removeAllMapLayers()
66+
67+
def testLine(self):
68+
line = next(self.lines_layer.getFeatures()).geometry()
69+
highlight = QgsHighlight(self.iface.mapCanvas(), line, self.lines_layer)
70+
color = QColor(Qt.red)
71+
highlight.setColor(color)
72+
color.setAlpha(50)
73+
highlight.setFillColor(color)
74+
highlight.show()
75+
image = QImage(QSize(400, 400), QImage.Format_ARGB32)
76+
painter = QPainter()
77+
painter.begin(image)
78+
self.iface.mapCanvas().render(painter)
79+
painter.end()
80+
81+
def testPolygon(self):
82+
poly = next(self.polys_layer.getFeatures()).geometry()
83+
self.iface.mapCanvas().setExtent(self.polys_layer.extent())
84+
highlight = QgsHighlight(self.iface.mapCanvas(), poly, self.polys_layer)
85+
color = QColor(Qt.red)
86+
highlight.setColor(color)
87+
color.setAlpha(50)
88+
highlight.setFillColor(color)
89+
highlight.show()
90+
image = QImage(QSize(400, 400), QImage.Format_ARGB32)
91+
painter = QPainter()
92+
painter.begin(image)
93+
self.iface.mapCanvas().render(painter)
94+
painter.end()
95+
96+
97+
98+
if __name__ == '__main__':
99+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.