[processing] Allow alg tests to use ParameterTable inputs

This commit is contained in:
Nyall Dawson 2016-11-24 07:52:17 +10:00
parent 7726205dc3
commit 69e8e4a3c2
2 changed files with 16 additions and 5 deletions

View File

@ -56,7 +56,8 @@ from processing.core.parameters import (
ParameterFile,
ParameterString,
ParameterNumber,
ParameterBoolean
ParameterBoolean,
ParameterTable
)
@ -172,6 +173,16 @@ def createTest(text):
if not schema:
p['location'] = '[The source data is not in the testdata directory. Please use data in the processing/tests/testdata folder.]'
params[param.name] = p
if isinstance(param, ParameterTable):
schema, filepath = extractSchemaPath(token)
p = {
'type': 'table',
'name': filepath
}
if not schema:
p['location'] = '[The source data is not in the testdata directory. Please use data in the processing/tests/testdata folder.]'
params[param.name] = p
elif isinstance(param, ParameterMultipleInput):
multiparams = token.split(';')

View File

@ -137,7 +137,7 @@ class AlgorithmsTest(object):
parameter based on its key `type` and return the appropriate parameter to pass to the algorithm.
"""
try:
if param['type'] == 'vector' or param['type'] == 'raster':
if param['type'] in ('vector', 'raster', 'table'):
return self.load_layer(param)
elif param['type'] == 'multi':
return [self.load_param(p) for p in param['params']]
@ -154,7 +154,7 @@ class AlgorithmsTest(object):
Loads a result parameter. Creates a temporary destination where the result should go to and returns this location
so it can be sent to the algorithm as parameter.
"""
if param['type'] in ['vector', 'file', 'regex']:
if param['type'] in ['vector', 'file', 'table', 'regex']:
outdir = tempfile.mkdtemp()
self.cleanup_paths.append(outdir)
basename = os.path.basename(param['name'])
@ -175,7 +175,7 @@ class AlgorithmsTest(object):
"""
filepath = self.filepath_from_param(param)
if param['type'] == 'vector':
if param['type'] in ('vector', 'table'):
lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
elif param['type'] == 'raster':
lyr = QgsRasterLayer(filepath, param['name'], 'gdal')
@ -199,7 +199,7 @@ class AlgorithmsTest(object):
Checks if result produced by an algorithm matches with the expected specification.
"""
for id, expected_result in list(expected.items()):
if 'vector' == expected_result['type']:
if expected_result['type'] in ('vector', 'table'):
expected_lyr = self.load_layer(expected_result)
try:
results[id]