|
28 | 28 | import os
|
29 | 29 | from qgis.testing import start_app, unittest
|
30 | 30 | from qgis.core import (QgsVectorLayer,
|
31 |
| - QgsProject, |
32 |
| - QgsRectangle, |
33 |
| - QgsMultiRenderChecker, |
34 |
| - QgsSingleSymbolRenderer, |
35 |
| - QgsFillSymbol, |
36 |
| - QgsFeatureRequest |
| 31 | + QgsFeature, |
| 32 | + QgsGeometry, |
| 33 | + QgsPoint |
37 | 34 | )
|
38 | 35 | from qgis.testing import unittest
|
39 | 36 | from qgis.testing.mocked import get_iface
|
|
43 | 40 |
|
44 | 41 | TEST_DATA_DIR = unitTestDataPath()
|
45 | 42 |
|
| 43 | + |
| 44 | +def createLayerWithOneLine(): |
| 45 | + # create a temporary layer |
| 46 | + # linelayer = iface.addVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory") |
| 47 | + linelayer = QgsVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory") |
| 48 | + one = QgsFeature(linelayer.dataProvider().fields(), 0) |
| 49 | + one.setAttributes([1, 'one']) |
| 50 | + one.setGeometry(QgsGeometry.fromPolyline([QgsPoint(-7, 38), QgsPoint(-8, 42)])) |
| 51 | + linelayer.dataProvider().addFeatures([one]) |
| 52 | + return linelayer |
| 53 | + |
| 54 | + |
46 | 55 | class TestQgsSymbolLayerReadSld(unittest.TestCase):
|
47 | 56 |
|
48 | 57 | """
|
49 |
| - This class loads an SLD style and checks if the styling was properly applied |
| 58 | + This class checks if SLD styles are properly applied |
50 | 59 | """
|
51 | 60 |
|
52 | 61 | def setUp(self):
|
53 | 62 | self.iface = get_iface()
|
54 |
| - myShpFile = os.path.join(TEST_DATA_DIR, 'streams.shp') |
55 |
| - self.layer = QgsVectorLayer(myShpFile, 'streams', 'ogr') |
| 63 | + |
| 64 | + # test <CSSParameter>VALUE<CSSParameter/> |
| 65 | + # test <CSSParameter><ogc:Literal>VALUE<ogc:Literal/><CSSParameter/> |
| 66 | + def test_Literal_within_CSSParameter(self): |
| 67 | + layer = createLayerWithOneLine() |
56 | 68 | mFilePath = os.path.join(TEST_DATA_DIR, 'symbol_layer/external_sld/simple_streams.sld')
|
57 |
| - self.layer.loadSldStyle(mFilePath) |
58 |
| - self.props = self.layer.rendererV2().symbol().symbolLayers()[0].properties() |
59 |
| - |
60 |
| - def testLineColor(self): |
61 |
| - # stroke CSSParameter within ogc:Literal |
62 |
| - # expected color is #003EBA, RGB 0,62,186 |
63 |
| - self.assertEqual(self.layer.rendererV2().symbol().symbolLayers()[0].color().name(), '#003eba') |
64 |
| - |
65 |
| - def testLineWidth(self): |
66 |
| - # stroke-width CSSParameter within ogc:Literal |
67 |
| - self.assertEqual(self.props['line_width'], '2') |
68 |
| - |
69 |
| - def testLineOpacity(self): |
70 |
| - # stroke-opacity CSSParameter NOT within ogc:Literal |
71 |
| - # stroke-opacity=0.1 |
72 |
| - self.assertEqual(self.props['line_color'], '0,62,186,25') |
| 69 | + layer.loadSldStyle(mFilePath) |
| 70 | + props = layer.rendererV2().symbol().symbolLayers()[0].properties() |
| 71 | + |
| 72 | + def testLineColor(): |
| 73 | + # stroke CSSParameter within ogc:Literal |
| 74 | + # expected color is #003EBA, RGB 0,62,186 |
| 75 | + self.assertEqual(layer.rendererV2().symbol().symbolLayers()[0].color().name(), '#003eba') |
| 76 | + |
| 77 | + def testLineWidth(): |
| 78 | + # stroke-width CSSParameter within ogc:Literal |
| 79 | + self.assertEqual(props['line_width'], '2') |
| 80 | + |
| 81 | + def testLineOpacity(): |
| 82 | + # stroke-opacity CSSParameter NOT within ogc:Literal |
| 83 | + # stroke-opacity=0.1 |
| 84 | + self.assertEqual(props['line_color'], '0,62,186,25') |
| 85 | + |
| 86 | + testLineColor() |
| 87 | + testLineWidth() |
| 88 | + testLineOpacity() |
73 | 89 |
|
74 | 90 | if __name__ == '__main__':
|
75 | 91 | unittest.main()
|
0 commit comments