Skip to content

Commit 6afb8de

Browse files
committed
Add a test for saveNamedStyle to file path
1 parent 08f2a02 commit 6afb8de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/src/python/test_qgsmaplayer.py

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# This will get replaced with a git SHA1 when you do a git archive
1313
__revision__ = '$Format:%H$'
1414

15+
import os
1516
import qgis # NOQA
1617
import tempfile
1718

@@ -20,6 +21,7 @@
2021
QgsProject)
2122
from qgis.testing import start_app, unittest
2223
from qgis.PyQt.QtXml import QDomDocument
24+
from qgis.PyQt.QtCore import QTemporaryDir
2325

2426
start_app()
2527

@@ -105,6 +107,15 @@ def testReadWriteMetadata(self):
105107
self.assertTrue(status)
106108
self.assertTrue(layer2.metadata().abstract(), 'My abstract')
107109

110+
def testSaveNamedStyle(self):
111+
layer = QgsVectorLayer("Point?field=fldtxt:string", "layer", "memory")
112+
dir = QTemporaryDir()
113+
dir_path = dir.path()
114+
style_path = os.path.join(dir_path, 'my.qml')
115+
_, result = layer.saveNamedStyle(style_path)
116+
self.assertTrue(result)
117+
self.assertTrue(os.path.exists(style_path))
118+
108119

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

0 commit comments

Comments
 (0)