Skip to content

Commit a8cdde5

Browse files
committedJun 23, 2017
Add test that python exception is caught when executing an alg
1 parent eb39fb0 commit a8cdde5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,28 @@
3030
import nose2
3131
import shutil
3232

33+
from qgis.core import (QgsProcessingAlgorithm,
34+
QgsProcessingFeedback)
3335
from qgis.testing import start_app, unittest
36+
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
37+
from processing.tools.dataobjects import createContext
38+
39+
40+
class TestAlg(QgsProcessingAlgorithm):
41+
42+
def __init__(self):
43+
super().__init__()
44+
45+
def name(self):
46+
return 'testalg'
47+
48+
def displayName(self):
49+
return 'testalg'
50+
51+
def processAlgorithm(self, parameters, context, feedback):
52+
raise GeoAlgorithmExecutionException(
53+
self.tr('Exception while processing'))
54+
return {}
3455

3556

3657
class TestQgisAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
@@ -52,6 +73,17 @@ def tearDownClass(cls):
5273
def test_definition_file(self):
5374
return 'qgis_algorithm_tests.yaml'
5475

76+
def testProcessingException(self):
77+
"""
78+
Test that Python exception is caught when running an alg
79+
"""
80+
81+
alg = TestAlg()
82+
context = createContext()
83+
feedback = QgsProcessingFeedback()
84+
results, ok = alg.run({}, context, feedback)
85+
self.assertFalse(ok)
86+
5587

5688
if __name__ == '__main__':
5789
nose2.main()

‎python/plugins/processing/tools/dataobjects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
TYPE_TABLE = 5
6666

6767

68-
def createContext(feedback):
68+
def createContext(feedback=None):
6969
"""
7070
Creates a default processing context
7171
"""

0 commit comments

Comments
 (0)
Please sign in to comment.