Skip to content

Commit c3e24b7

Browse files
committedJun 23, 2017
Fix some processing tests where output is not generated or should
not be compared
1 parent 5ea0768 commit c3e24b7

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed
 

‎python/plugins/processing/tests/AlgorithmsTestBase.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def check_algorithm(self, name, defs):
114114
parameters[k] = p
115115

116116
for r, p in list(defs['results'].items()):
117-
parameters[r] = self.load_result_param(p)
117+
if not 'in_place_result' in p or not p['in_place_result']:
118+
parameters[r] = self.load_result_param(p)
118119

119120
expectFailure = False
120121
if 'expectedFailure' in defs:
@@ -136,7 +137,7 @@ def check_algorithm(self, name, defs):
136137
pass
137138
else:
138139
results, ok = alg.run(parameters, context, feedback)
139-
self.assertTrue(ok)
140+
self.assertTrue(ok, parameters)
140141
self.check_results(results, context, defs['params'], defs['results'])
141142

142143
def load_params(self, params):
@@ -202,26 +203,23 @@ def load_layer(self, id, param):
202203
"""
203204
filepath = self.filepath_from_param(param)
204205

205-
try:
206+
if 'in_place' in param and param['in_place']:
206207
# check if alg modifies layer in place
207-
if param['in_place']:
208-
tmpdir = tempfile.mkdtemp()
209-
self.cleanup_paths.append(tmpdir)
210-
path, file_name = os.path.split(filepath)
211-
base, ext = os.path.splitext(file_name)
212-
for file in glob.glob(os.path.join(path, '{}.*'.format(base))):
213-
shutil.copy(os.path.join(path, file), tmpdir)
214-
filepath = os.path.join(tmpdir, file_name)
215-
self.in_place_layers[id] = filepath
216-
except:
217-
pass
208+
tmpdir = tempfile.mkdtemp()
209+
self.cleanup_paths.append(tmpdir)
210+
path, file_name = os.path.split(filepath)
211+
base, ext = os.path.splitext(file_name)
212+
for file in glob.glob(os.path.join(path, '{}.*'.format(base))):
213+
shutil.copy(os.path.join(path, file), tmpdir)
214+
filepath = os.path.join(tmpdir, file_name)
215+
self.in_place_layers[id] = filepath
218216

219217
if param['type'] in ('vector', 'table'):
220218
lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
221219
elif param['type'] == 'raster':
222220
lyr = QgsRasterLayer(filepath, param['name'], 'gdal')
223221

224-
self.assertTrue(lyr.isValid(), 'Could not load layer "{}"'.format(filepath))
222+
self.assertTrue(lyr.isValid(), 'Could not load layer "{}" from param {}'.format(filepath, param))
225223
QgsProject.instance().addMapLayer(lyr)
226224
return lyr
227225

@@ -241,6 +239,12 @@ def check_results(self, results, context, params, expected):
241239
"""
242240
for id, expected_result in list(expected.items()):
243241
if expected_result['type'] in ('vector', 'table'):
242+
if 'compare' in expected_result and not expected_result['compare']:
243+
# skipping the comparison, so just make sure output is valid
244+
result_lyr = QgsProcessingUtils.mapLayerFromString(results[id], context)
245+
self.assertTrue(result_lyr.isValid())
246+
continue
247+
244248
expected_lyr = self.load_layer(id, expected_result)
245249
if 'in_place_result' in expected_result:
246250
result_lyr = QgsProcessingUtils.mapLayerFromString(self.in_place_layers[id], context)

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,11 @@ tests:
25732573
type: vector
25742574
METHOD: 0
25752575
NUMBER: 4
2576-
results: {}
2576+
results:
2577+
OUTPUT:
2578+
type: vector
2579+
name: points_weighted.gml
2580+
compare: false
25772581

25782582
- algorithm: qgis:randomextract
25792583
name: Random extract by percentage
@@ -2583,4 +2587,8 @@ tests:
25832587
type: vector
25842588
METHOD: 1
25852589
NUMBER: 50
2586-
results: {}
2590+
results:
2591+
OUTPUT:
2592+
type: vector
2593+
name: points_weighted.gml
2594+
compare: false

0 commit comments

Comments
 (0)
Please sign in to comment.