mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Allow specifying multiple possible vector layer results for processing
tests Some algorithms are non-deterministic and the results may vary from run to run. In this case we allow specifying multiple possible valid results, and the test will pass if the result layer matches any of these.
This commit is contained in:
parent
e8d667cac3
commit
9968962ab9
@ -43,6 +43,7 @@ import tempfile
|
||||
|
||||
from osgeo.gdalconst import GA_ReadOnly
|
||||
from numpy import nan_to_num
|
||||
from copy import deepcopy
|
||||
|
||||
import processing
|
||||
|
||||
@ -186,7 +187,10 @@ class AlgorithmsTest(object):
|
||||
if param['type'] in ['vector', 'file', 'table', 'regex']:
|
||||
outdir = tempfile.mkdtemp()
|
||||
self.cleanup_paths.append(outdir)
|
||||
basename = os.path.basename(param['name'])
|
||||
if isinstance(param['name'], str):
|
||||
basename = os.path.basename(param['name'])
|
||||
else:
|
||||
basename = os.path.basename(param['name'][0])
|
||||
filepath = os.path.join(outdir, basename)
|
||||
return filepath
|
||||
elif param['type'] == 'rasterhash':
|
||||
@ -198,6 +202,19 @@ class AlgorithmsTest(object):
|
||||
|
||||
raise KeyError("Unknown type '{}' specified for parameter".format(param['type']))
|
||||
|
||||
def load_layers(self, id, param):
|
||||
layers = []
|
||||
if param['type'] in ('vector', 'table') and isinstance(param['name'], str):
|
||||
layers.append(self.load_layer(id, param))
|
||||
elif param['type'] in ('vector', 'table'):
|
||||
for n in param['name']:
|
||||
layer_param = deepcopy(param)
|
||||
layer_param['name'] = n
|
||||
layers.append(self.load_layer(id, layer_param))
|
||||
else:
|
||||
layers.append(self.load_layer(id, param))
|
||||
return layers
|
||||
|
||||
def load_layer(self, id, param):
|
||||
"""
|
||||
Loads a layer which was specified as parameter.
|
||||
@ -253,7 +270,7 @@ class AlgorithmsTest(object):
|
||||
self.assertTrue(result_lyr.isValid())
|
||||
continue
|
||||
|
||||
expected_lyr = self.load_layer(id, expected_result)
|
||||
expected_lyrs = self.load_layers(id, expected_result)
|
||||
if 'in_place_result' in expected_result:
|
||||
result_lyr = QgsProcessingUtils.mapLayerFromString(self.in_place_layers[id], context)
|
||||
self.assertTrue(result_lyr.isValid(), self.in_place_layers[id])
|
||||
@ -271,7 +288,15 @@ class AlgorithmsTest(object):
|
||||
|
||||
compare = expected_result.get('compare', {})
|
||||
|
||||
self.assertLayersEqual(expected_lyr, result_lyr, compare=compare)
|
||||
if len(expected_lyrs) == 1:
|
||||
self.assertLayersEqual(expected_lyrs[0], result_lyr, compare=compare)
|
||||
else:
|
||||
res = False
|
||||
for l in expected_lyrs:
|
||||
if self.checkLayersEqual(l, result_lyr, compare=compare):
|
||||
res = True
|
||||
break
|
||||
self.assertTrue(res, 'Could not find matching layer in expected results')
|
||||
|
||||
elif 'rasterhash' == expected_result['type']:
|
||||
print("id:{} result:{}".format(id, results[id]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user