Skip to content

Commit 467f3f0

Browse files
committed
More documentation for processing tests
1 parent 8582f61 commit 467f3f0

File tree

1 file changed

+84
-50
lines changed

1 file changed

+84
-50
lines changed

python/plugins/processing/tests/README.md

+84-50
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ A basic test appears under the toplevel key `tests` and looks like this:
1111
algorithm: qgis:polygoncentroids
1212
params:
1313
- type: vector
14-
location: qgs
15-
name: polys.shp
14+
name: polys.gml
1615
results:
17-
- id: OUTPUT_LAYER
16+
OUTPUT_LAYER:
1817
type: vector
19-
location: proc
20-
name: polys_centroid.geojson
18+
name: expected/polys_centroid.gml
2119

2220
How To
2321
------
@@ -30,13 +28,11 @@ geometry types and good readability. Redirect output to
3028
`python/plugins/processing/tests/testdata/expected`
3129

3230
When you have run the algorithm, go to "Processing" > "History" and find the
33-
algorithm which you have just run. This looks like
34-
35-
processing.runalg("qgis:densifygeometries","/home/mku/dev/cpp/qgis/QGIS/tests/testdata/polys.shp",2,"/home/mku/dev/cpp/qgis/QGIS/python/plugins/processing/tests/testdata/polys_densify.geojson")
31+
algorithm which you have just run. Right click the algorithm and click "Create test".
32+
A new window will open with a text definition.
3633

3734
Open the file `python/plugins/processing/tests/testdata/algorithm_tests.yaml`,
38-
copy an existing test block and adjust it to your needs based on the
39-
information found in the history.
35+
copy the text definition there.
4036

4137
The first string from the command goes to the key `algorithm`, the subsequent
4238
ones to params and the last one(s) to results.
@@ -47,72 +43,110 @@ The above translates to
4743
algorithm: qgis:densifygeometriesgivenaninterval
4844
params:
4945
- type: vector
50-
location: qgs
51-
name: polys.shp
46+
name: polys.gml
5247
- 2 # Interval
5348
results:
54-
- id: OUTPUT
49+
OUTPUT:
5550
type: vector
56-
location: proc
57-
name: expected/polys_densify.geojson
51+
name: expected/polys_densify.gml
5852

5953
Params and results
6054
------------------
6155

62-
Trivial type parameters
63-
.......................
56+
### Trivial type parameters
57+
58+
Params and results are specified as lists or dictionaries:
6459

65-
Params and results are specified as lists:
60+
params:
61+
INTERVAL: 5
62+
INTERPOLATE: True
63+
NAME: A processing test
64+
65+
or
6666

6767
params:
6868
- 2
6969
- string
7070
- another param
7171

72-
As in the example above they can be plain variables.
73-
74-
Layer type parameters
75-
.....................
72+
### Layer type parameters
7673

77-
To specify layers you will have to specify
74+
You will often need to specify layers as parameters. To specify a layer you will need to specify:
7875

7976
* the type
8077
* `vector` or `raster`
81-
* a location to allow using files from the shared qgis test data
82-
* `qgs` will look for the file in the src/tests/testdata
83-
* `proc` will look for the file in python/plugins/processing/tests/testdata
84-
you should use this location for expected data.
8578
* a name
86-
* relative path like `expected/polys_centroid.geojson`
79+
* relative path like `expected/polys_centroid.gml`
8780

8881
params:
89-
- 2
90-
- string
91-
- type: vector
92-
location: qgs
93-
name: polys.shp
94-
- another param
82+
PAR: 2
83+
STR: string
84+
LAYER:
85+
type: vector
86+
name: polys.gml
87+
OTHER: another param
9588

96-
Results
97-
.......
89+
### Results
9890

99-
Results have a special key `id` which is required because an algorithm can
100-
produce multiple results. If you don't know the `id`, just start with `OUTPUT`
101-
and run the test. You will be told if it was wrong and about the possible
102-
values.
91+
Results are specified very similar.
10392

104-
To deal with a certain tolerance for output values you can specify a
105-
`compare` property for an output.
93+
#### Basic vector files
94+
95+
It couldn't be more trivial
96+
97+
OUTPUT:
98+
name: expected/qgis_intersection.gml
99+
type: vector
100+
101+
#### Vector with tolerance
106102

107-
For a vector layer this means
103+
Sometimes different platforms create slightly different results which are
104+
still acceptable. In this case (but only then) you may also use additional
105+
properties to define how exactly a layer is compared.
106+
107+
To deal with a certain tolerance for output values you can specify a
108+
`compare` property for an output. The compare property can contain sub-properties
109+
for `fields`. This contains information about how precisely a certain field is
110+
compared (`precision`) or a field can even entirely be `skip`ed. There is a special
111+
field name `__all__` which will apply a certain tolerance to all fields.
112+
There is another property `geometry` which also accepts a `precision` which is
113+
applied to each vertex.
108114

109115
OUTPUT:
110116
type: vector
111117
name: expected/abcd.geojson
112-
compare:
113-
fields:
114-
__all__:
115-
precision: 5 # compare to a precision of .00001 on all fields
116-
A: skip # skip field A
117-
geometry:
118-
precision: 5 # compare coordinates with a precision of 5 digits
118+
compare:
119+
fields:
120+
__all__:
121+
precision: 5 # compare to a precision of .00001 on all fields
122+
A: skip # skip field A
123+
geometry:
124+
precision: 5 # compare coordinates with a precision of 5 digits
125+
126+
#### Raster files
127+
128+
Raster files are compared with a hash checksum. This is calculated when you create
129+
a test from the processing history.
130+
131+
OUTPUT:
132+
type: rasterhash
133+
hash: f1fedeb6782f9389cf43590d4c85ada9155ab61fef6dc285aaeb54d6
134+
135+
#### Files
136+
137+
You can compare the content of an ouptut file by an expected result reference file
138+
139+
OUTPUT_HTML_FILE:
140+
name: expected/basic_statistics_string.html
141+
type: file
142+
143+
Or you can use one or more regular expressions that will be [matched](https://docs.python.org/2/library/re.html#re.search) against the file
144+
content
145+
146+
OUTPUT:
147+
name: expected/gdal/layer_info.html
148+
type: regex
149+
rules:
150+
- 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
151+
- 'Geometry: Line String'
152+
- 'Feature Count: 6'

0 commit comments

Comments
 (0)