Skip to content
Permalink
Browse files

Add test for rendering order

  • Loading branch information
m-kuhn committed Dec 21, 2015
1 parent 168c6f7 commit e00815db33589a84bb9ba6f69dd1fe94fcb2f412
@@ -54,6 +54,7 @@ ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
ADD_PYTHON_TEST(PyQgsRectangle test_qgsrectangle.py)
ADD_PYTHON_TEST(PyQgsRelation test_qgsrelation.py)
ADD_PYTHON_TEST(PyQgsRulebasedRenderer test_qgsrulebasedrenderer.py)
ADD_PYTHON_TEST(PyQgsSingleSymbolRenderer test_qgssinglesymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsShapefileProvider test_provider_shapefile.py)
ADD_PYTHON_TEST(PyQgsSpatialIndex test_qgsspatialindex.py)
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
test_qgssinglesymbolrenderer.py
---------------------
Date : December 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__ = 'December 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,
QgsSingleSymbolRendererV2,
QgsFillSymbolV2,
QgsMarkerSymbolV2,
QgsRendererCategoryV2,
QgsCategorizedSymbolRendererV2,
QgsGraduatedSymbolRendererV2,
QgsRendererRangeV2,
QgsFeatureRequest
)
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 TestQgsSingleSymbolRenderer(TestCase):

def setUp(self):
myShpFile = os.path.join(TEST_DATA_DIR, 'polys_overlapping.shp')
layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)

# Create rulebased style
sym1 = QgsFillSymbolV2.createSimple({'color': '#fdbf6f'})

self.renderer = QgsSingleSymbolRendererV2(sym1)
layer.setRendererV2(self.renderer)

rendered_layers = [layer.id()]
self.mapsettings = CANVAS.mapSettings()
self.mapsettings.setOutputSize(QSize(400, 400))
self.mapsettings.setOutputDpi(96)
self.mapsettings.setExtent(QgsRectangle(-163, 22, -70, 52))
self.mapsettings.setLayers(rendered_layers)

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

def testOrderBy(self):
self.renderer.setOrderBy(QgsFeatureRequest.OrderBy([QgsFeatureRequest.OrderByClause('Value', False)]))

# Setup rendering check
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlName('expected_singlesymbol_orderby')
result = renderchecker.runTest('singlesymbol_orderby')

assert result

if __name__ == '__main__':
unittest.main()
Binary file not shown.

0 comments on commit e00815d

Please sign in to comment.
You can’t perform that action at this time.