29
29
import shutil
30
30
31
31
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 )
33
42
from qgis .testing import start_app , unittest
34
43
35
44
from processing .algs .saga .SagaParameters import Parameters , SagaImageOutputParam
@@ -45,6 +54,9 @@ def setUpClass(cls):
45
54
Processing .initialize ()
46
55
cls .cleanup_paths = []
47
56
57
+ cls .temp_dir = tempfile .mkdtemp ()
58
+ cls .cleanup_paths .append (cls .temp_dir )
59
+
48
60
@classmethod
49
61
def tearDownClass (cls ):
50
62
from processing .core .Processing import Processing
@@ -82,6 +94,49 @@ def test_param_line(self):
82
94
self .assertEqual (param .defaultFileExtension (), 'tif' )
83
95
self .assertEqual (param .supportedOutputRasterLayerExtensions (), ['tif' ])
84
96
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
+
85
140
86
141
if __name__ == '__main__' :
87
142
nose2 .main ()
0 commit comments