From 69e8e4a3c237bd7a240912ccd54c93a4a166e167 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 24 Nov 2016 07:52:17 +1000 Subject: [PATCH] [processing] Allow alg tests to use ParameterTable inputs --- python/plugins/processing/gui/TestTools.py | 13 ++++++++++++- .../plugins/processing/tests/AlgorithmsTestBase.py | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/python/plugins/processing/gui/TestTools.py b/python/plugins/processing/gui/TestTools.py index e5f0ebe5e2d..4eff30dd969 100644 --- a/python/plugins/processing/gui/TestTools.py +++ b/python/plugins/processing/gui/TestTools.py @@ -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(';') diff --git a/python/plugins/processing/tests/AlgorithmsTestBase.py b/python/plugins/processing/tests/AlgorithmsTestBase.py index 73f4fae66fb..64f87b31ad8 100644 --- a/python/plugins/processing/tests/AlgorithmsTestBase.py +++ b/python/plugins/processing/tests/AlgorithmsTestBase.py @@ -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]