Skip to content

Commit 1f21af6

Browse files
Médéric RibreuxMédéric RIBREUX
authored andcommittedMay 29, 2016
Improve tests: add external file support into AlgorithmsTest
1 parent e70f9bc commit 1f21af6

File tree

11 files changed

+460
-1
lines changed

11 files changed

+460
-1
lines changed
 

‎python/plugins/processing/tests/AlgorithmsTestBase.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ def load_param(self, param):
136136
try:
137137
if param['type'] == 'vector' or param['type'] == 'raster':
138138
return self.load_layer(param)
139-
if param['type'] == 'multi':
139+
elif param['type'] == 'multi':
140140
return [self.load_param(p) for p in param['params']]
141+
elif param['type'] == 'file':
142+
return self.filepath_from_param(param)
141143
except TypeError:
142144
# No type specified, use whatever is there
143145
return param

‎python/plugins/processing/tests/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ params:
9898
OTHER: another param
9999
```
100100

101+
### File type parameters
102+
103+
If you need an external file for the algorithm test, you need to specify the 'file' type and the (relative) path to the file in its 'name':
104+
105+
```yaml
106+
params:
107+
PAR: 2
108+
STR: string
109+
EXTFILE:
110+
type: file
111+
name: custom/grass7/extfile.txt
112+
OTHER: another param
113+
```
114+
101115
### Results
102116

103117
Results are specified very similar.
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<PAMDataset>
2+
<PAMRasterBand band="1">
3+
<Histograms>
4+
<HistItem>
5+
<HistMin>-310.575</HistMin>
6+
<HistMax>14854.575</HistMax>
7+
<BucketCount>1000</BucketCount>
8+
<IncludeOutOfRange>0</IncludeOutOfRange>
9+
<Approximate>0</Approximate>
10+
<HistCounts>8|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|15|15|15|16|15|15|8</HistCounts>
11+
</HistItem>
12+
</Histograms>
13+
<Metadata>
14+
<MDI key="STATISTICS_MAXIMUM">14847</MDI>
15+
<MDI key="STATISTICS_MEAN">7272</MDI>
16+
<MDI key="STATISTICS_MINIMUM">-303</MDI>
17+
<MDI key="STATISTICS_STDDEV">4373.7169547194</MDI>
18+
</Metadata>
19+
</PAMRasterBand>
20+
</PAMDataset>
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<PAMDataset>
2+
<PAMRasterBand band="1">
3+
<Histograms>
4+
<HistItem>
5+
<HistMin>0.6</HistMin>
6+
<HistMax>5.4</HistMax>
7+
<BucketCount>5</BucketCount>
8+
<IncludeOutOfRange>0</IncludeOutOfRange>
9+
<Approximate>0</Approximate>
10+
<HistCounts>2999|921|2110|4010|5000</HistCounts>
11+
</HistItem>
12+
</Histograms>
13+
<Metadata>
14+
<MDI key="COLOR_TABLE_RULES_COUNT">5</MDI>
15+
<MDI key="COLOR_TABLE_RULE_RGB_0">1.000000e+00 1.800000e+00 255 255 0 0 255 0</MDI>
16+
<MDI key="COLOR_TABLE_RULE_RGB_1">1.800000e+00 2.600000e+00 0 255 0 0 255 255</MDI>
17+
<MDI key="COLOR_TABLE_RULE_RGB_2">2.600000e+00 3.400000e+00 0 255 255 0 0 255</MDI>
18+
<MDI key="COLOR_TABLE_RULE_RGB_3">3.400000e+00 4.200000e+00 0 0 255 255 0 255</MDI>
19+
<MDI key="COLOR_TABLE_RULE_RGB_4">4.200000e+00 5.000000e+00 255 0 255 255 0 0</MDI>
20+
<MDI key="Generated_with">GRASS GIS 7.0.3</MDI>
21+
<MDI key="STATISTICS_MAXIMUM">5</MDI>
22+
<MDI key="STATISTICS_MEAN">3.4714760638298</MDI>
23+
<MDI key="STATISTICS_MINIMUM">1</MDI>
24+
<MDI key="STATISTICS_STDDEV">1.4943102023375</MDI>
25+
</Metadata>
26+
</PAMRasterBand>
27+
</PAMDataset>
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<PAMDataset>
2+
<PAMRasterBand band="1">
3+
<Histograms>
4+
<HistItem>
5+
<HistMin>0.5833333333333333</HistMin>
6+
<HistMax>6.416666666666667</HistMax>
7+
<BucketCount>6</BucketCount>
8+
<IncludeOutOfRange>0</IncludeOutOfRange>
9+
<Approximate>0</Approximate>
10+
<HistCounts>1999|920|2110|3010|1960|5001</HistCounts>
11+
</HistItem>
12+
</Histograms>
13+
<Metadata>
14+
<MDI key="COLOR_TABLE_RULES_COUNT">5</MDI>
15+
<MDI key="COLOR_TABLE_RULE_RGB_0">1.000000e+00 2.000000e+00 255 255 0 0 255 0</MDI>
16+
<MDI key="COLOR_TABLE_RULE_RGB_1">2.000000e+00 3.000000e+00 0 255 0 0 255 255</MDI>
17+
<MDI key="COLOR_TABLE_RULE_RGB_2">3.000000e+00 4.000000e+00 0 255 255 0 0 255</MDI>
18+
<MDI key="COLOR_TABLE_RULE_RGB_3">4.000000e+00 5.000000e+00 0 0 255 255 0 255</MDI>
19+
<MDI key="COLOR_TABLE_RULE_RGB_4">5.000000e+00 6.000000e+00 255 0 255 255 0 0</MDI>
20+
<MDI key="Generated_with">GRASS GIS 7.0.3</MDI>
21+
<MDI key="STATISTICS_MAXIMUM">6</MDI>
22+
<MDI key="STATISTICS_MEAN">4.1343333333333</MDI>
23+
<MDI key="STATISTICS_MINIMUM">1</MDI>
24+
<MDI key="STATISTICS_STDDEV">1.7411551401935</MDI>
25+
</Metadata>
26+
</PAMRasterBand>
27+
</PAMDataset>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
#
3+
300
4+
7043.06
5+
1.89772e+07
6+
#
7+
1700
8+
7405.93
9+
2.01921e+07
10+
#
11+
6000
12+
7287.21
13+
1.90221e+07
14+
#
15+
7000
16+
7246.81
17+
1.90226e+07
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
title:
2+
nbands: 1
3+
class:
4+
classnum: 1
5+
classtitle:
6+
classtype: 1
7+
subclass:
8+
pi: 0.22802
9+
means: 9764.5
10+
covar:
11+
3.02234e+06
12+
endsubclass:
13+
subclass:
14+
pi: 0.495197
15+
means: 5208.5
16+
covar:
17+
7.97435e+06
18+
endsubclass:
19+
subclass:
20+
pi: 0.118668
21+
means: 997.979
22+
covar:
23+
686411
24+
endsubclass:
25+
subclass:
26+
pi: 0.158115
27+
means: 13401
28+
covar:
29+
702077
30+
endsubclass:
31+
endclass:
32+
class:
33+
classnum: 2
34+
classtitle:
35+
classtype: 1
36+
subclass:
37+
pi: 0.177696
38+
means: 13267.4
39+
covar:
40+
1.06971e+06
41+
endsubclass:
42+
subclass:
43+
pi: 0.172485
44+
means: 3861.81
45+
covar:
46+
2.35556e+06
47+
endsubclass:
48+
subclass:
49+
pi: 0.48383
50+
means: 8696.48
51+
covar:
52+
7.62681e+06
53+
endsubclass:
54+
subclass:
55+
pi: 0.165989
56+
means: 1052.05
57+
covar:
58+
692627
59+
endsubclass:
60+
endclass:
61+
class:
62+
classnum: 3
63+
classtitle:
64+
classtype: 1
65+
subclass:
66+
pi: 0.135816
67+
means: 1158.36
68+
covar:
69+
934515
70+
endsubclass:
71+
subclass:
72+
pi: 0.187835
73+
means: 11847.9
74+
covar:
75+
1.74438e+06
76+
endsubclass:
77+
subclass:
78+
pi: 0.0829488
79+
means: 14066.2
80+
covar:
81+
268579
82+
endsubclass:
83+
subclass:
84+
pi: 0.5934
85+
means: 6298.74
86+
covar:
87+
8.66516e+06
88+
endsubclass:
89+
endclass:
90+
class:
91+
classnum: 4
92+
classtitle:
93+
classtype: 1
94+
subclass:
95+
pi: 0.278456
96+
means: 3394.59
97+
covar:
98+
2.33337e+06
99+
endsubclass:
100+
subclass:
101+
pi: 0.0849227
102+
means: 13998.4
103+
covar:
104+
256746
105+
endsubclass:
106+
subclass:
107+
pi: 0.102818
108+
means: 686.099
109+
covar:
110+
379342
111+
endsubclass:
112+
subclass:
113+
pi: 0.222279
114+
means: 11683.6
115+
covar:
116+
1.75208e+06
117+
endsubclass:
118+
subclass:
119+
pi: 0.311523
120+
means: 7849.26
121+
covar:
122+
3.21781e+06
123+
endsubclass:
124+
endclass:

‎python/plugins/processing/tests/testdata/grass7_algorithm_tests.yaml

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,231 @@ tests:
236236
output:
237237
hash: 270bbef9dd111af5df23a819cb0848e104e0cf4949e794a67fa0b3f2
238238
type: rasterhash
239+
240+
- algorithm: grass7:i.group
241+
name: GRASS7 i.group
242+
params:
243+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
244+
input:
245+
type: multi
246+
params:
247+
- name: custom/grass7/raster_6class.tif
248+
type: raster
249+
- name: custom/grass7/raster_5class.tif
250+
type: raster
251+
- name: custom/grass7/raster_4class.tif
252+
type: raster
253+
results:
254+
group:
255+
hash: e1a433546cc1fdf7061adc0d9b77676c9d66ee8e0773d471bdb39a37
256+
type: rasterhash
257+
258+
- algorithm: grass7:i.cluster
259+
name: GRASS7 i.cluster
260+
params:
261+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
262+
classes: 5
263+
convergence: 98
264+
input:
265+
params:
266+
- name: custom/grass7/raster_6class.tif
267+
type: raster
268+
- name: custom/grass7/raster_5class.tif
269+
type: raster
270+
- name: custom/grass7/raster_4class.tif
271+
type: raster
272+
type: multi
273+
iterations: 30
274+
min_size: 17
275+
separation: 0
276+
results:
277+
signaturefile:
278+
type: regex
279+
name: expected/grass7/i.cluster.sig.txt
280+
rules:
281+
- '#Class 1'
282+
- '1.83333 1.53759 3.31579'
283+
- '#Class 2'
284+
- '2.11045 4.35498 3.32266'
285+
- '#Class 3'
286+
- '5.32655 1.72558 3.32713'
287+
- '#Class 4'
288+
- '4.34567 4.36522 3.30235'
289+
- '#Class 5'
290+
- '6 4.55734 3.30291'
291+
292+
- algorithm: grass7:i.oif
293+
name: GRASS7 i.oif
294+
params:
295+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
296+
input:
297+
params:
298+
- name: custom/grass7/float_raster.tif
299+
type: raster
300+
- name: custom/grass7/raster_6class.tif
301+
type: raster
302+
- name: custom/grass7/raster_5class.tif
303+
type: raster
304+
- name: custom/grass7/raster_4class.tif
305+
type: raster
306+
type: multi
307+
results:
308+
output:
309+
type: regex
310+
name: expected/grass7/i.oif.txt
311+
rules:
312+
- '118773.1947'
313+
- '4541.9055'
314+
- '4369.2930'
315+
- '128.6900'
316+
317+
- algorithm: grass7:i.fft
318+
name: GRASS7 i.fft
319+
params:
320+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
321+
input:
322+
name: custom/grass7/float_raster.tif
323+
type: raster
324+
results:
325+
imaginary:
326+
hash: 94249384dd8b6019f0024501bc9a093cba9dd025c183d3fb46d77027
327+
type: rasterhash
328+
real:
329+
hash: 09ab93c65aa2dde4da422b62a5ed3e38208e2da072cec2b0eb837a47
330+
type: rasterhash
331+
332+
- algorithm: grass7:i.segment
333+
name: GRASS7 i.segment
334+
params:
335+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
336+
input:
337+
params:
338+
- name: custom/grass7/raster_6class.tif
339+
type: raster
340+
- name: custom/grass7/raster_5class.tif
341+
type: raster
342+
- name: custom/grass7/raster_4class.tif
343+
type: raster
344+
type: multi
345+
iterations: 20
346+
memory: 300
347+
method: 0
348+
minsize: 1
349+
similarity: 0
350+
threshold: 0.5
351+
results:
352+
goodness:
353+
hash: 5cb3cc31a68c03ea76578559b04ffa5f81331a4232abb38d09b29ea4
354+
type: rasterhash
355+
output:
356+
hash: b65992a5d48b867d4a32a533f38e7a72cb1ba18f1e261c6be132baca
357+
type: rasterhash
358+
359+
- algorithm: grass7:i.gensig
360+
name: GRASS7 i.gensig
361+
params:
362+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
363+
input:
364+
params:
365+
- name: custom/grass7/float_raster.tif
366+
type: raster
367+
type: multi
368+
trainingmap:
369+
name: custom/grass7/raster_4class.tif
370+
type: raster
371+
results:
372+
signaturefile:
373+
type: file
374+
name: expected/grass7/i.gensig.txt
375+
376+
- algorithm: grass7:i.gensigset
377+
name: GRASS7 i.gensigset
378+
params:
379+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
380+
input:
381+
params:
382+
- name: custom/grass7/float_raster.tif
383+
type: raster
384+
type: multi
385+
maxsig: 5
386+
trainingmap:
387+
name: custom/grass7/raster_4class.tif
388+
type: raster
389+
results:
390+
signaturefile:
391+
type: file
392+
name: expected/grass7/i.gensigset.txt
393+
394+
- algorithm: grass7:i.rgb.his
395+
name: GRASS7 i.rgb.his
396+
params:
397+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
398+
blue:
399+
name: custom/grass7/raster_6class.tif
400+
type: raster
401+
green:
402+
name: custom/grass7/raster_5class.tif
403+
type: raster
404+
red:
405+
name: custom/grass7/raster_4class.tif
406+
type: raster
407+
results:
408+
hue:
409+
hash: d82c717b0aca5c7bb49d6f2b086a188a6fbdc397c533734911261f74
410+
type: rasterhash
411+
intensity:
412+
hash: 6d75d7a40460611301a1f2c2b162d08ae20fb5527d80509f19748b3c
413+
type: rasterhash
414+
saturation:
415+
hash: 07578ad38cf948473a519f040acb0235f60a592904ac8ef46aa607e1
416+
type: rasterhash
417+
418+
- algorithm: grass7:i.pansharpen
419+
name: GRASS7 i.pansharpen
420+
params:
421+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
422+
blue:
423+
name: custom/grass7/raster_4class.tif
424+
type: raster
425+
green:
426+
name: custom/grass7/raster_5class.tif
427+
type: raster
428+
method: 2
429+
pan:
430+
name: custom/grass7/float_raster.tif
431+
type: raster
432+
red:
433+
name: custom/grass7/raster_6class.tif
434+
type: raster
435+
results:
436+
blueoutput:
437+
hash: b8f6f6d11751ec26eb93daed87611e473efe6146ad3e84bce13c3393
438+
type: rasterhash
439+
greenoutput:
440+
hash: 522356ef99242f7be6ad65c23af9148f5a807deca89c1efec1db38c1
441+
type: rasterhash
442+
redoutput:
443+
hash: c6b99e12c2eab3016bbf8d15888c353c3fdb1b84674deac78e3e2bfc
444+
type: rasterhash
445+
446+
# Don't work, needs to handle external files in tests code
447+
- algorithm: grass7:i.smap
448+
name: GRASS7 i.smap
449+
params:
450+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
451+
blocksize: 1024
452+
input:
453+
params:
454+
- name: custom/grass7/float_raster.tif
455+
type: raster
456+
type: multi
457+
signaturefile:
458+
type: file
459+
name: expected/grass7/i.gensigset.txt
460+
results:
461+
goodness:
462+
hash: 26c3f407312e8a9e03e91c32e526f71ea9cfa78037a90a5f78f0818e
463+
type: rasterhash
464+
output:
465+
hash: f9e99ac3891b23c650add0478bb5225444183c61c6a4c321a7c2a16f
466+
type: rasterhash

0 commit comments

Comments
 (0)
Please sign in to comment.