Skip to content

Commit

Permalink
[processing] Allow alg tests to use ParameterTable inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 23, 2016
1 parent 7726205 commit 69e8e4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion python/plugins/processing/gui/TestTools.py
Expand Up @@ -56,7 +56,8 @@
ParameterFile,
ParameterString,
ParameterNumber,
ParameterBoolean
ParameterBoolean,
ParameterTable
)


Expand Down Expand Up @@ -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(';')
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/tests/AlgorithmsTestBase.py
Expand Up @@ -137,7 +137,7 @@ def load_param(self, param):
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']]
Expand All @@ -154,7 +154,7 @@ def load_result_param(self, param):
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'])
Expand All @@ -175,7 +175,7 @@ def load_layer(self, param):
"""
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')
Expand All @@ -199,7 +199,7 @@ def check_results(self, results, expected):
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]
Expand Down

0 comments on commit 69e8e4a

Please sign in to comment.