Skip to content
Permalink
Browse files

Fix some processing tests where output is not generated or should

not be compared
  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent 5ea0768 commit c3e24b76b544fd5c5f49e3774896e268066a2d02
@@ -114,7 +114,8 @@ def check_algorithm(self, name, defs):
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 @@ def check_algorithm(self, name, defs):
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 @@ def load_layer(self, id, param):
"""
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 @@ def check_results(self, results, context, params, expected):
"""
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)
@@ -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

0 comments on commit c3e24b7

Please sign in to comment.
You can’t perform that action at this time.