Skip to content

Commit

Permalink
Fix exec statement for AlgorithmsTestBase.py
Browse files Browse the repository at this point in the history
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 authored and Médéric RIBREUX committed May 29, 2016
1 parent 5f3b60c commit c867123
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions python/plugins/processing/tests/AlgorithmsTestBase.py
Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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':
Expand All @@ -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)
Expand Down

0 comments on commit c867123

Please sign in to comment.