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() QgsMapLayerRegistry.instance().removeAllMapLayers()


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

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


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


expectFailure = False expectFailure = False
if 'expectedFailure' in defs: 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]) expectFailure = eval(defs['expectedFailure'][-1])


def doCheck():
alg.execute()

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

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


def load_params(self, params): 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. Loads a layer which was specified as parameter.
""" """
filepath = self.filepath_from_param(param) filepath = self.filepath_from_param(param)

if param['type'] == 'vector': if param['type'] == 'vector':
lyr = QgsVectorLayer(filepath, param['name'], 'ogr') lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
elif param['type'] == 'raster': 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. Checks if result produced by an algorithm matches with the expected specification.
""" """

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

0 comments on commit c867123

Please sign in to comment.