29
29
from qgis .core import (QgsApplication ,
30
30
QgsCoordinateReferenceSystem ,
31
31
QgsProcessingParameterMatrix ,
32
+ QgsProcessingOutputLayerDefinition ,
33
+ QgsProcessingParameterFeatureSink ,
34
+ QgsProcessingParameterFileDestination ,
35
+ QgsProcessingParameterFolderDestination ,
36
+ QgsProcessingParameterVectorDestination ,
37
+ QgsProcessingParameterRasterDestination ,
32
38
QgsVectorLayer ,
33
39
QgsProject )
34
40
from qgis .analysis import QgsNativeAlgorithms
37
43
from processing .gui .BatchAlgorithmDialog import BatchAlgorithmDialog
38
44
from processing .modeler .ModelerParametersDialog import ModelerParametersDialog
39
45
from processing .gui .wrappers import *
46
+ from processing .gui .DestinationSelectionPanel import DestinationSelectionPanel
40
47
41
48
start_app ()
42
49
QgsApplication .processingRegistry ().addProvider (QgsNativeAlgorithms ())
43
50
51
+ testDataPath = os .path .join (os .path .dirname (__file__ ), 'testdata' )
52
+
44
53
45
54
class AlgorithmDialogTest (unittest .TestCase ):
46
55
@@ -52,6 +61,10 @@ def testCreation(self):
52
61
53
62
class WrappersTest (unittest .TestCase ):
54
63
64
+ @classmethod
65
+ def setUpClass (cls ):
66
+ ProcessingConfig .initialize ()
67
+
55
68
def checkConstructWrapper (self , param , expected_wrapper_class ):
56
69
alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
57
70
@@ -270,6 +283,118 @@ def testNumber(self):
270
283
def testBand (self ):
271
284
self .checkConstructWrapper (QgsProcessingParameterBand ('test' ), BandWidgetWrapper )
272
285
286
+ def testFeatureSink (self ):
287
+ param = QgsProcessingParameterFeatureSink ('test' )
288
+ alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
289
+ panel = DestinationSelectionPanel (param , alg )
290
+
291
+ panel .setValue ('memory:' )
292
+ v = panel .getValue ()
293
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
294
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
295
+ self .assertEqual (v .sink .staticValue (), 'memory:' )
296
+
297
+ panel .setValue ('''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''' )
298
+ v = panel .getValue ()
299
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
300
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
301
+ self .assertEqual (v .sink .staticValue (), '''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''' )
302
+
303
+ panel .setValue ('''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''' )
304
+ v = panel .getValue ()
305
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
306
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
307
+ self .assertEqual (v .sink .staticValue (), '''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''' )
308
+
309
+ panel .setValue ('/home/me/test.shp' )
310
+ v = panel .getValue ()
311
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
312
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
313
+ self .assertEqual (v .sink .staticValue (), '/home/me/test.shp' )
314
+
315
+ ProcessingConfig .setSettingValue (ProcessingConfig .OUTPUT_FOLDER , testDataPath )
316
+ panel .setValue ('test.shp' )
317
+ v = panel .getValue ()
318
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
319
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
320
+ self .assertEqual (v .sink .staticValue (), os .path .join (testDataPath , 'test.shp' ))
321
+
322
+ def testVectorDestination (self ):
323
+ param = QgsProcessingParameterVectorDestination ('test' )
324
+ alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
325
+ panel = DestinationSelectionPanel (param , alg )
326
+
327
+ panel .setValue ('''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''' )
328
+ v = panel .getValue ()
329
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
330
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
331
+ self .assertEqual (v .sink .staticValue (), '''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''' )
332
+
333
+ panel .setValue ('''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''' )
334
+ v = panel .getValue ()
335
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
336
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
337
+ self .assertEqual (v .sink .staticValue (), '''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''' )
338
+
339
+ panel .setValue ('/home/me/test.shp' )
340
+ v = panel .getValue ()
341
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
342
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
343
+ self .assertEqual (v .sink .staticValue (), '/home/me/test.shp' )
344
+
345
+ ProcessingConfig .setSettingValue (ProcessingConfig .OUTPUT_FOLDER , testDataPath )
346
+ panel .setValue ('test.shp' )
347
+ v = panel .getValue ()
348
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
349
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
350
+ self .assertEqual (v .sink .staticValue (), os .path .join (testDataPath , 'test.shp' ))
351
+
352
+ def testRasterDestination (self ):
353
+ param = QgsProcessingParameterRasterDestination ('test' )
354
+ alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
355
+ panel = DestinationSelectionPanel (param , alg )
356
+
357
+ panel .setValue ('/home/me/test.tif' )
358
+ v = panel .getValue ()
359
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
360
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
361
+ self .assertEqual (v .sink .staticValue (), '/home/me/test.tif' )
362
+
363
+ ProcessingConfig .setSettingValue (ProcessingConfig .OUTPUT_FOLDER , testDataPath )
364
+ panel .setValue ('test.tif' )
365
+ v = panel .getValue ()
366
+ self .assertIsInstance (v , QgsProcessingOutputLayerDefinition )
367
+ self .assertEqual (v .createOptions , {'fileEncoding' : 'System' })
368
+ self .assertEqual (v .sink .staticValue (), os .path .join (testDataPath , 'test.tif' ))
369
+
370
+ def testFolderDestination (self ):
371
+ param = QgsProcessingParameterFolderDestination ('test' )
372
+ alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
373
+ panel = DestinationSelectionPanel (param , alg )
374
+
375
+ panel .setValue ('/home/me/test.tif' )
376
+ v = panel .getValue ()
377
+ self .assertEqual (v , '/home/me/test.tif' )
378
+
379
+ ProcessingConfig .setSettingValue (ProcessingConfig .OUTPUT_FOLDER , testDataPath )
380
+ panel .setValue ('test.tif' )
381
+ v = panel .getValue ()
382
+ self .assertEqual (v , os .path .join (testDataPath , 'test.tif' ))
383
+
384
+ def testFileDestination (self ):
385
+ param = QgsProcessingParameterFileDestination ('test' )
386
+ alg = QgsApplication .processingRegistry ().algorithmById ('native:centroids' )
387
+ panel = DestinationSelectionPanel (param , alg )
388
+
389
+ panel .setValue ('/home/me/test.tif' )
390
+ v = panel .getValue ()
391
+ self .assertEqual (v , '/home/me/test.tif' )
392
+
393
+ ProcessingConfig .setSettingValue (ProcessingConfig .OUTPUT_FOLDER , testDataPath )
394
+ panel .setValue ('test.tif' )
395
+ v = panel .getValue ()
396
+ self .assertEqual (v , os .path .join (testDataPath , 'test.tif' ))
397
+
273
398
274
399
if __name__ == '__main__' :
275
400
unittest .main ()
0 commit comments