Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for rulebased renderer else rule
- Loading branch information
Showing
10 changed files
with
147 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
test_qgsrulebasedrenderer.py | ||
--------------------- | ||
Date : September 2015 | ||
Copyright : (C) 2015 by Matthias Kuhn | ||
Email : matthias at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* 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__ = 'September 2015' | ||
__copyright__ = '(C) 2015, Matthiasd Kuhn' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis | ||
import os | ||
|
||
from PyQt4.QtCore import QSize | ||
|
||
from qgis.core import (QgsVectorLayer, | ||
QgsMapLayerRegistry, | ||
QgsRectangle, | ||
QgsMultiRenderChecker, | ||
QgsRuleBasedRendererV2, | ||
QgsFillSymbolV2 | ||
) | ||
from utilities import (unitTestDataPath, | ||
getQgisTestApp, | ||
TestCase, | ||
unittest | ||
) | ||
# Convenience instances in case you may need them | ||
# not used in this test | ||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() | ||
TEST_DATA_DIR = unitTestDataPath() | ||
|
||
|
||
class TestQgsRulebasedRenderer(TestCase): | ||
|
||
def setUp(self): | ||
myShpFile = os.path.join(TEST_DATA_DIR, 'rectangles.shp') | ||
layer = QgsVectorLayer(myShpFile, 'Points', 'ogr') | ||
QgsMapLayerRegistry.instance().addMapLayer(layer) | ||
|
||
# Create rulebased style | ||
sym1 = QgsFillSymbolV2.createSimple({'color': '#fdbf6f'}) | ||
sym2 = QgsFillSymbolV2.createSimple({'color': '#71bd6c'}) | ||
sym3 = QgsFillSymbolV2.createSimple({'color': '#1f78b4'}) | ||
|
||
self.r1 = QgsRuleBasedRendererV2.Rule(sym1, 0, 0, '"id" = 1') | ||
self.r2 = QgsRuleBasedRendererV2.Rule(sym2, 0, 0, '"id" = 2') | ||
self.r3 = QgsRuleBasedRendererV2.Rule(sym3, 0, 0, 'ELSE') | ||
|
||
self.rootrule = QgsRuleBasedRendererV2.Rule(None) | ||
self.rootrule.appendChild(self.r1) | ||
self.rootrule.appendChild(self.r2) | ||
self.rootrule.appendChild(self.r3) | ||
|
||
self.renderer = QgsRuleBasedRendererV2(self.rootrule) | ||
layer.setRendererV2(self.renderer) | ||
self.mapsettings = CANVAS.mapSettings() | ||
self.mapsettings.setOutputSize(QSize(400, 400)) | ||
self.mapsettings.setOutputDpi(96) | ||
self.mapsettings.setExtent(QgsRectangle(-163, 22, -70, 52)) | ||
|
||
rendered_layers = [layer.id()] | ||
self.mapsettings.setLayers(rendered_layers) | ||
|
||
def tearDown(self): | ||
QgsMapLayerRegistry.instance().removeAllMapLayers() | ||
|
||
def testElse(self): | ||
# Setup rendering check | ||
renderchecker = QgsMultiRenderChecker() | ||
renderchecker.setMapSettings(self.mapsettings) | ||
renderchecker.setControlName('expected_rulebased_else') | ||
result = renderchecker.runTest('rulebased_else') | ||
|
||
assert result | ||
|
||
def testDisabledElse(self): | ||
# Disable a rule and assert that it's hidden not rendered with else | ||
self.r2.setActive(False) | ||
|
||
renderchecker = QgsMultiRenderChecker() | ||
renderchecker.setMapSettings(self.mapsettings) | ||
renderchecker.setControlName('expected_rulebased_disabled_else') | ||
result = renderchecker.runTest('rulebased_disabled_else') | ||
|
||
assert result | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Binary file added
BIN
+460 KB
...ol_images/expected_rulebased_disabled_else/expected_rulebased_disabled_else.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+460 KB
tests/testdata/control_images/expected_rulebased_else/expected_rulebased_else.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] |
Binary file not shown.
Binary file not shown.