Skip to content

Commit

Permalink
add tests for style URI retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 24, 2019
1 parent c13bd14 commit 80cb853
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/src/python/test_qgsmaplayer.py
Expand Up @@ -22,6 +22,9 @@
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtCore import QTemporaryDir
from utilities import unitTestDataPath

TEST_DATA_DIR = unitTestDataPath()

start_app()

Expand Down Expand Up @@ -116,6 +119,27 @@ def testSaveNamedStyle(self):
self.assertTrue(result)
self.assertTrue(os.path.exists(style_path))

def testStyleUri(self):
# shapefile
layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'points.shp'), "layer", "ogr")
uri = layer.styleURI()
self.assertEqual(uri, os.path.join(TEST_DATA_DIR, 'points.qml'))

# geopackage without and with layername
layer = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'provider', 'bug_17795.gpkg'), "layer", "ogr")
uri = layer.styleURI()
self.assertEqual(uri, os.path.join(TEST_DATA_DIR, 'provider', 'bug_17795.qml'))

layer = QgsVectorLayer("{}|layername=bug_17795".format(os.path.join(TEST_DATA_DIR, 'provider', 'bug_17795.gpkg')), "layer", "ogr")
uri = layer.styleURI()
self.assertEqual(uri, os.path.join(TEST_DATA_DIR, 'provider', 'bug_17795.qml'))

# delimited text
uri = 'file://{}?type=csv&detectTypes=yes&geomType=none'.format(os.path.join(TEST_DATA_DIR, 'delimitedtext', 'test.csv'))
layer = QgsVectorLayer(uri, "layer", "delimitedtext")
uri = layer.styleURI()
self.assertEqual(uri, os.path.join(TEST_DATA_DIR, 'delimitedtext', 'test.qml'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 80cb853

Please sign in to comment.