Skip to content

Commit

Permalink
DDL update: saving layer styles on databases
Browse files Browse the repository at this point in the history
Fix #11421
  • Loading branch information
jgrocha committed Jan 18, 2017
1 parent 5c2fec3 commit 65c0177
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
64 changes: 39 additions & 25 deletions tests/src/python/test_qgssymbollayer_readsld.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
import os
from qgis.testing import start_app, unittest
from qgis.core import (QgsVectorLayer,
QgsProject,
QgsRectangle,
QgsMultiRenderChecker,
QgsSingleSymbolRenderer,
QgsFillSymbol,
QgsFeatureRequest
QgsFeature,
QgsGeometry,
QgsPoint
)
from qgis.testing import unittest
from qgis.testing.mocked import get_iface
Expand All @@ -43,33 +40,50 @@

TEST_DATA_DIR = unitTestDataPath()

def createLayerWithOneLine():
# create a temporary layer
# linelayer = iface.addVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory")
linelayer = QgsVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory")
one = QgsFeature(linelayer.dataProvider().fields(), 0)
one.setAttributes([1, 'one'])
one.setGeometry(QgsGeometry.fromPolyline([QgsPoint(-7, 38), QgsPoint(-8, 42)]))
linelayer.dataProvider().addFeatures([one])
return linelayer

class TestQgsSymbolLayerReadSld(unittest.TestCase):

"""
This class loads an SLD style and checks if the styling was properly applied
This class checks if SLD styles are properly applied
"""

def setUp(self):
self.iface = get_iface()
myShpFile = os.path.join(TEST_DATA_DIR, 'streams.shp')
self.layer = QgsVectorLayer(myShpFile, 'streams', 'ogr')

# test <CSSParameter>VALUE<CSSParameter/>
# test <CSSParameter><ogc:Literal>VALUE<ogc:Literal/><CSSParameter/>
def test_Literal_within_CSSParameter(self):
layer = createLayerWithOneLine()
mFilePath = os.path.join(TEST_DATA_DIR, 'symbol_layer/external_sld/simple_streams.sld')
self.layer.loadSldStyle(mFilePath)
self.props = self.layer.renderer().symbol().symbolLayers()[0].properties()

def testLineColor(self):
# stroke CSSParameter within ogc:Literal
# expected color is #003EBA, RGB 0,62,186
self.assertEqual(self.layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')

def testLineWidth(self):
# stroke-width CSSParameter within ogc:Literal
self.assertEqual(self.props['line_width'], '2')

def testLineOpacity(self):
# stroke-opacity CSSParameter NOT within ogc:Literal
# stroke-opacity=0.1
self.assertEqual(self.props['line_color'], '0,62,186,25')
layer.loadSldStyle(mFilePath)
props = layer.renderer().symbol().symbolLayers()[0].properties()

def testLineColor():
# stroke CSSParameter within ogc:Literal
# expected color is #003EBA, RGB 0,62,186
self.assertEqual(layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')

def testLineWidth():
# stroke-width CSSParameter within ogc:Literal
self.assertEqual(props['line_width'], '2')

def testLineOpacity():
# stroke-opacity CSSParameter NOT within ogc:Literal
# stroke-opacity=0.1
self.assertEqual(props['line_color'], '0,62,186,25')

testLineColor()
testLineWidth()
testLineOpacity()

if __name__ == '__main__':
unittest.main()
Binary file removed tests/testdata/streams.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion tests/testdata/streams.prj

This file was deleted.

Binary file removed tests/testdata/streams.shp
Binary file not shown.
Binary file removed tests/testdata/streams.shx
Binary file not shown.

0 comments on commit 65c0177

Please sign in to comment.