@@ -11,13 +11,11 @@ A basic test appears under the toplevel key `tests` and looks like this:
11
11
algorithm: qgis: polygoncentroids
12
12
params:
13
13
- type: vector
14
- location: qgs
15
- name: polys.shp
14
+ name: polys.gml
16
15
results:
17
- - id: OUTPUT_LAYER
16
+ OUTPUT_LAYER:
18
17
type: vector
19
- location: proc
20
- name: polys_centroid.geojson
18
+ name: expected/polys_centroid.gml
21
19
22
20
How To
23
21
------
@@ -30,13 +28,11 @@ geometry types and good readability. Redirect output to
30
28
` python/plugins/processing/tests/testdata/expected `
31
29
32
30
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.
36
33
37
34
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.
40
36
41
37
The first string from the command goes to the key ` algorithm ` , the subsequent
42
38
ones to params and the last one(s) to results.
@@ -47,72 +43,110 @@ The above translates to
47
43
algorithm: qgis:densifygeometriesgivenaninterval
48
44
params:
49
45
- type: vector
50
- location: qgs
51
- name: polys.shp
46
+ name: polys.gml
52
47
- 2 # Interval
53
48
results:
54
- - id: OUTPUT
49
+ OUTPUT:
55
50
type: vector
56
- location: proc
57
- name: expected/polys_densify.geojson
51
+ name: expected/polys_densify.gml
58
52
59
53
Params and results
60
54
------------------
61
55
62
- Trivial type parameters
63
- .......................
56
+ ### Trivial type parameters
57
+
58
+ Params and results are specified as lists or dictionaries:
64
59
65
- Params and results are specified as lists:
60
+ params:
61
+ INTERVAL: 5
62
+ INTERPOLATE: True
63
+ NAME: A processing test
64
+
65
+ or
66
66
67
67
params:
68
68
- 2
69
69
- string
70
70
- another param
71
71
72
- As in the example above they can be plain variables.
73
-
74
- Layer type parameters
75
- .....................
72
+ ### Layer type parameters
76
73
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:
78
75
79
76
* the type
80
77
* ` 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.
85
78
* a name
86
- * relative path like ` expected/polys_centroid.geojson `
79
+ * relative path like ` expected/polys_centroid.gml `
87
80
88
81
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
95
88
96
- Results
97
- .......
89
+ ### Results
98
90
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.
103
92
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
106
102
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.
108
114
109
115
OUTPUT:
110
116
type: vector
111
117
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