Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4268 from alexbruy/scripts-tests
[processing] support for scripts in the test suite
- Loading branch information
Showing
10 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
ScriptAlgorithmsTests.py | ||
--------------------- | ||
Date : March 2017 | ||
Copyright : (C) 2017 by Alexander Bruy | ||
Email : alexander dot bruy at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Alexander Bruy' | ||
__date__ = 'March 2017' | ||
__copyright__ = '(C) 2017, Alexander Bruy' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = ':%H$' | ||
|
||
import AlgorithmsTestBase | ||
|
||
import nose2 | ||
import shutil | ||
|
||
from qgis.testing import start_app, unittest | ||
|
||
|
||
class TestScriptAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
start_app() | ||
from processing.core.Processing import Processing | ||
Processing.initialize() | ||
cls.cleanup_paths = [] | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
for path in cls.cleanup_paths: | ||
shutil.rmtree(path) | ||
|
||
def test_definition_file(self): | ||
return 'script_algorithm_tests.yaml' | ||
|
||
|
||
if __name__ == '__main__': | ||
nose2.main() |
26 changes: 26 additions & 0 deletions
26
python/plugins/processing/tests/testdata/expected/selected_points.gfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<GMLFeatureClassList> | ||
<GMLFeatureClass> | ||
<Name>selected_points</Name> | ||
<ElementPath>selected_points</ElementPath> | ||
<!--POINT--> | ||
<GeometryType>1</GeometryType> | ||
<SRSName>EPSG:4326</SRSName> | ||
<DatasetSpecificInfo> | ||
<FeatureCount>2</FeatureCount> | ||
<ExtentXMin>1.00000</ExtentXMin> | ||
<ExtentXMax>5.00000</ExtentXMax> | ||
<ExtentYMin>1.00000</ExtentYMin> | ||
<ExtentYMax>2.00000</ExtentYMax> | ||
</DatasetSpecificInfo> | ||
<PropertyDefn> | ||
<Name>id</Name> | ||
<ElementPath>id</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
<PropertyDefn> | ||
<Name>id2</Name> | ||
<ElementPath>id2</ElementPath> | ||
<Type>Integer</Type> | ||
</PropertyDefn> | ||
</GMLFeatureClass> | ||
</GMLFeatureClassList> |
28 changes: 28 additions & 0 deletions
28
python/plugins/processing/tests/testdata/expected/selected_points.gml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ogr:FeatureCollection | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="" | ||
xmlns:ogr="http://ogr.maptools.org/" | ||
xmlns:gml="http://www.opengis.net/gml"> | ||
<gml:boundedBy> | ||
<gml:Box> | ||
<gml:coord><gml:X>1</gml:X><gml:Y>1</gml:Y></gml:coord> | ||
<gml:coord><gml:X>5</gml:X><gml:Y>2</gml:Y></gml:coord> | ||
</gml:Box> | ||
</gml:boundedBy> | ||
|
||
<gml:featureMember> | ||
<ogr:selected_points fid="points.0"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:id>1</ogr:id> | ||
<ogr:id2>2</ogr:id2> | ||
</ogr:selected_points> | ||
</gml:featureMember> | ||
<gml:featureMember> | ||
<ogr:selected_points fid="points.3"> | ||
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty> | ||
<ogr:id>4</ogr:id> | ||
<ogr:id2>2</ogr:id2> | ||
</ogr:selected_points> | ||
</gml:featureMember> | ||
</ogr:FeatureCollection> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
python/plugins/processing/tests/testdata/script_algorithm_tests.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# See ../README.md for a description of the file format | ||
|
||
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 |
29 changes: 29 additions & 0 deletions
29
python/plugins/processing/tests/testdata/scripts/centroids.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
##Centroids=name | ||
##Geometry=group | ||
##INPUT_LAYER=vector | ||
##OUTPUT_LAYER=output vector | ||
|
||
from qgis.core import QgsWkbTypes, QgsGeometry | ||
|
||
from processing.tools.vector import VectorWriter | ||
|
||
layer = processing.getObject(INPUT_LAYER) | ||
fields = layer.fields() | ||
|
||
writer = VectorWriter(OUTPUT_LAYER, 'utf-8', fields, QgsWkbTypes.Point, layer.crs()) | ||
|
||
features = processing.features(layer) | ||
count = len(features) | ||
if count == 0: | ||
raise GeoAlgorithmExecutionException('Input layer contains no features.') | ||
|
||
total = 100.0 / len(features) | ||
|
||
for count, f in enumerate(features): | ||
outputFeature = f | ||
if f.hasGeometry(): | ||
outputGeometry = f.geometry().centroid() | ||
outputFeature.setGeometry(outputGeometry) | ||
|
||
writer.addFeature(outputFeature) | ||
feedback.setProgress(int(count * total)) |
16 changes: 16 additions & 0 deletions
16
python/plugins/processing/tests/testdata/scripts/selectbyattribute.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
##Select by attribute=name | ||
##Tests=group | ||
##INPUT_LAYER=vector | ||
##OUTPUT_LAYER=output vector | ||
|
||
import processing | ||
|
||
result = processing.runalg("qgis:selectbyattribute", | ||
INPUT_LAYER, | ||
"id2", | ||
0, | ||
"2") | ||
|
||
processing.runalg("qgis:saveselectedfeatures", | ||
result["OUTPUT"], | ||
OUTPUT_LAYER) |