From 792a252ef8d8654816422fd5d7884650a93fe75c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 27 Jun 2017 11:12:20 +1000 Subject: [PATCH] Fix script algorithm centroids tests --- .../testdata/script_algorithm_tests.yaml | 26 +++++++++---------- .../tests/testdata/scripts/centroids.py | 23 ++++++++++------ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/python/plugins/processing/tests/testdata/script_algorithm_tests.yaml b/python/plugins/processing/tests/testdata/script_algorithm_tests.yaml index 6ff51fe7fc53..1d417a17dc5a 100644 --- a/python/plugins/processing/tests/testdata/script_algorithm_tests.yaml +++ b/python/plugins/processing/tests/testdata/script_algorithm_tests.yaml @@ -2,16 +2,16 @@ tests: -# - algorithm: script:centroids -# name: Centroids script test -# params: -# INPUT_LAYER: -# name: polys.gml -# type: vector -# results: -# OUTPUT_LAYER: -# name: expected/centroid_polys.gml -# type: vector -# compare: -# geometry: -# precision: 7 + - algorithm: script:centroids + name: Centroids script test + params: + INPUT_LAYER: + name: polys.gml + type: vector + results: + OUTPUT_LAYER: + name: expected/centroid_polys.gml + type: vector + compare: + geometry: + precision: 7 diff --git a/python/plugins/processing/tests/testdata/scripts/centroids.py b/python/plugins/processing/tests/testdata/scripts/centroids.py index 70b76dedb452..a8dc13be9e7f 100644 --- a/python/plugins/processing/tests/testdata/scripts/centroids.py +++ b/python/plugins/processing/tests/testdata/scripts/centroids.py @@ -1,17 +1,24 @@ ##Centroids=name ##Geometry=group -##INPUT_LAYER=vector -##OUTPUT_LAYER=output vector + +#inputs + +##INPUT_LAYER=source +##OUTPUT_LAYER=sink point + +#outputs + +##OUTPUT_LAYER=output outputVector from qgis.core import QgsWkbTypes, QgsProcessingUtils -layer = QgsProcessingUtils.mapLayerFromString(INPUT_LAYER, context) -fields = layer.fields() +fields = INPUT_LAYER.fields() -writer, writer_dest = QgsProcessingUtils.createFeatureSink(OUTPUT_LAYER, context, fields, QgsWkbTypes.Point, layer.crs(), {'fileEncoding': 'utf-8'}) +(sink, OUTPUT_LAYER) = self.parameterAsSink(parameters, 'OUTPUT_LAYER', context, + fields, QgsWkbTypes.Point, INPUT_LAYER.sourceCrs()) -features = QgsProcessingUtils.getFeatures(layer, context) -count = QgsProcessingUtils.featureCount(layer, context) +features = INPUT_LAYER.getFeatures() +count = INPUT_LAYER.featureCount() if count == 0: raise GeoAlgorithmExecutionException('Input layer contains no features.') @@ -23,5 +30,5 @@ outputGeometry = f.geometry().centroid() outputFeature.setGeometry(outputGeometry) - writer.addFeature(outputFeature) + sink.addFeature(outputFeature) feedback.setProgress(int(count * total))