Skip to content

Commit 8bbd559

Browse files
committedJan 25, 2019
[processing] added test for SAGA output to non-ascii files
1 parent d627b56 commit 8bbd559

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed
 

‎python/plugins/processing/tests/SagaAlgorithmsTest.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@
2929
import shutil
3030

3131
from qgis.core import (QgsProcessingParameterNumber,
32-
QgsProcessingParameterDefinition)
32+
QgsProcessingParameterDefinition,
33+
QgsVectorLayer,
34+
QgsApplication,
35+
QgsFeature,
36+
QgsGeometry,
37+
QgsPointXY,
38+
QgsProcessingContext,
39+
QgsProject,
40+
QgsProcessingFeedback,
41+
QgsProcessingFeatureSourceDefinition)
3342
from qgis.testing import start_app, unittest
3443

3544
from processing.algs.saga.SagaParameters import Parameters, SagaImageOutputParam
@@ -45,6 +54,9 @@ def setUpClass(cls):
4554
Processing.initialize()
4655
cls.cleanup_paths = []
4756

57+
cls.temp_dir = tempfile.mkdtemp()
58+
cls.cleanup_paths.append(cls.temp_dir)
59+
4860
@classmethod
4961
def tearDownClass(cls):
5062
from processing.core.Processing import Processing
@@ -82,6 +94,49 @@ def test_param_line(self):
8294
self.assertEqual(param.defaultFileExtension(), 'tif')
8395
self.assertEqual(param.supportedOutputRasterLayerExtensions(), ['tif'])
8496

97+
def test_non_ascii_output(self):
98+
# create a memory layer and add to project and context
99+
layer = QgsVectorLayer("Point?crs=epsg:3857&field=fldtxt:string&field=fldint:integer",
100+
"testmem", "memory")
101+
self.assertTrue(layer.isValid())
102+
pr = layer.dataProvider()
103+
f = QgsFeature()
104+
f.setAttributes(["test", 123])
105+
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
106+
f2 = QgsFeature()
107+
f2.setAttributes(["test2", 457])
108+
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(110, 200)))
109+
self.assertTrue(pr.addFeatures([f, f2]))
110+
self.assertEqual(layer.featureCount(), 2)
111+
QgsProject.instance().addMapLayer(layer)
112+
context = QgsProcessingContext()
113+
context.setProject(QgsProject.instance())
114+
115+
alg = QgsApplication.processingRegistry().createAlgorithmById('saga:fixeddistancebuffer')
116+
self.assertIsNotNone(alg)
117+
118+
temp_file = os.path.join(self.temp_dir, 'non_ascii_ñññ.gpkg')
119+
parameters = {'SHAPES':'testmem',
120+
'DIST_FIELD_DEFAULT':5,
121+
'NZONES':1,
122+
'DARC':5,
123+
'DISSOLVE':True,
124+
'POLY_INNER':False,
125+
'BUFFER':temp_file}
126+
feedback = QgsProcessingFeedback()
127+
128+
results, ok = alg.run(parameters, context, feedback)
129+
self.assertTrue(ok)
130+
self.assertTrue(os.path.exists(temp_file))
131+
132+
# make sure that layer has correct features
133+
res = QgsVectorLayer(temp_file, 'res')
134+
self.assertTrue(res.isValid())
135+
self.assertEqual(res.featureCount(), 2)
136+
137+
QgsProject.instance().removeMapLayer(layer)
138+
139+
85140

86141
if __name__ == '__main__':
87142
nose2.main()

0 commit comments

Comments
 (0)
Please sign in to comment.