From c3e24b76b544fd5c5f49e3774896e268066a2d02 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 23 Jun 2017 12:48:58 +1000 Subject: [PATCH] Fix some processing tests where output is not generated or should not be compared --- .../processing/tests/AlgorithmsTestBase.py | 34 +++++++++++-------- .../tests/testdata/qgis_algorithm_tests.yaml | 12 +++++-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/python/plugins/processing/tests/AlgorithmsTestBase.py b/python/plugins/processing/tests/AlgorithmsTestBase.py index 8a8aa2b4203..af475f8fa97 100644 --- a/python/plugins/processing/tests/AlgorithmsTestBase.py +++ b/python/plugins/processing/tests/AlgorithmsTestBase.py @@ -114,7 +114,8 @@ class AlgorithmsTest(object): parameters[k] = p for r, p in list(defs['results'].items()): - parameters[r] = self.load_result_param(p) + if not 'in_place_result' in p or not p['in_place_result']: + parameters[r] = self.load_result_param(p) expectFailure = False if 'expectedFailure' in defs: @@ -136,7 +137,7 @@ class AlgorithmsTest(object): pass else: results, ok = alg.run(parameters, context, feedback) - self.assertTrue(ok) + self.assertTrue(ok, parameters) self.check_results(results, context, defs['params'], defs['results']) def load_params(self, params): @@ -202,26 +203,23 @@ class AlgorithmsTest(object): """ filepath = self.filepath_from_param(param) - try: + if 'in_place' in param and param['in_place']: # check if alg modifies layer in place - if param['in_place']: - tmpdir = tempfile.mkdtemp() - self.cleanup_paths.append(tmpdir) - path, file_name = os.path.split(filepath) - base, ext = os.path.splitext(file_name) - for file in glob.glob(os.path.join(path, '{}.*'.format(base))): - shutil.copy(os.path.join(path, file), tmpdir) - filepath = os.path.join(tmpdir, file_name) - self.in_place_layers[id] = filepath - except: - pass + tmpdir = tempfile.mkdtemp() + self.cleanup_paths.append(tmpdir) + path, file_name = os.path.split(filepath) + base, ext = os.path.splitext(file_name) + for file in glob.glob(os.path.join(path, '{}.*'.format(base))): + shutil.copy(os.path.join(path, file), tmpdir) + filepath = os.path.join(tmpdir, file_name) + self.in_place_layers[id] = filepath if param['type'] in ('vector', 'table'): lyr = QgsVectorLayer(filepath, param['name'], 'ogr') elif param['type'] == 'raster': lyr = QgsRasterLayer(filepath, param['name'], 'gdal') - self.assertTrue(lyr.isValid(), 'Could not load layer "{}"'.format(filepath)) + self.assertTrue(lyr.isValid(), 'Could not load layer "{}" from param {}'.format(filepath, param)) QgsProject.instance().addMapLayer(lyr) return lyr @@ -241,6 +239,12 @@ class AlgorithmsTest(object): """ for id, expected_result in list(expected.items()): if expected_result['type'] in ('vector', 'table'): + if 'compare' in expected_result and not expected_result['compare']: + # skipping the comparison, so just make sure output is valid + result_lyr = QgsProcessingUtils.mapLayerFromString(results[id], context) + self.assertTrue(result_lyr.isValid()) + continue + expected_lyr = self.load_layer(id, expected_result) if 'in_place_result' in expected_result: result_lyr = QgsProcessingUtils.mapLayerFromString(self.in_place_layers[id], context) diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml index 1de103c6ba1..324077a3402 100644 --- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml +++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml @@ -2573,7 +2573,11 @@ tests: type: vector METHOD: 0 NUMBER: 4 - results: {} + results: + OUTPUT: + type: vector + name: points_weighted.gml + compare: false - algorithm: qgis:randomextract name: Random extract by percentage @@ -2583,4 +2587,8 @@ tests: type: vector METHOD: 1 NUMBER: 50 - results: {} + results: + OUTPUT: + type: vector + name: points_weighted.gml + compare: false