Skip to content
Permalink
Browse files

Fix exec statement for AlgorithmsTestBase.py

On travis-ci environment, Python version seems to be affected by [this bug](https://bugs.python.org/issue21591).
One way to fix it is to use the old statement instead of exec() function.
  • Loading branch information
Médéric Ribreux Médéric RIBREUX
Médéric Ribreux authored and Médéric RIBREUX committed May 26, 2016
1 parent 5f3b60c commit c867123f18e13b4c7542eecdadada25676f1a02d
Showing with 10 additions and 6 deletions.
  1. +10 −6 python/plugins/processing/tests/AlgorithmsTestBase.py
@@ -85,6 +85,7 @@ def check_algorithm(self, name, defs):
QgsMapLayerRegistry.instance().removeAllMapLayers()

params = self.load_params(defs['params'])

alg = processing.Processing.getAlgorithm(defs['algorithm']).getCopy()

if isinstance(params, list):
@@ -99,20 +100,23 @@ def check_algorithm(self, name, defs):

expectFailure = False
if 'expectedFailure' in defs:
exec('\n'.join(defs['expectedFailure'][:-1]), globals(), locals())
exec '\n'.join(defs['expectedFailure'][:-1]) in globals(), locals()
expectFailure = eval(defs['expectedFailure'][-1])

def doCheck():
alg.execute()

self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])

if expectFailure:
try:
alg.execute()
self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])
doCheck()
except Exception:
pass
else:
raise _UnexpectedSuccess
else:
alg.execute()
self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])
doCheck()

def load_params(self, params):
"""
@@ -168,6 +172,7 @@ def load_layer(self, param):
Loads a layer which was specified as parameter.
"""
filepath = self.filepath_from_param(param)

if param['type'] == 'vector':
lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
elif param['type'] == 'raster':
@@ -191,7 +196,6 @@ def check_results(self, results, expected):
"""
Checks if result produced by an algorithm matches with the expected specification.
"""

for id, expected_result in expected.items():
if 'vector' == expected_result['type']:
expected_lyr = self.load_layer(expected_result)

0 comments on commit c867123

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