Skip to content

Commit e94d9a5

Browse files
Rashad Kanavathnyalldawson
Rashad Kanavath
authored andcommitted
[TEST] add more test on otb segmentation apps
Even though not all errors are caught by these new tests, it could expose if otb is broken or if processing api is changed to adopt optional status of parameters at run-time. `alg.processAlgorithm()` is running and failing correctly. But `parameter.checkValueIsAcceptable()` and `alg.checkParameterValues()` aren't working as expected.
1 parent 0b86110 commit e94d9a5

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

python/plugins/processing/tests/OtbAlgorithmsTest.py

+63
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import tempfile
3535
from qgis.core import (QgsProcessingParameterNumber,
3636
QgsApplication,
37+
QgsRasterLayer,
3738
QgsMapLayer,
3839
QgsProject,
3940
QgsProcessingContext,
@@ -58,6 +59,68 @@
5859

5960
class TestOtbAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
6061

62+
@staticmethod
63+
def __input_raster_layer():
64+
options = QgsRasterLayer.LayerOptions()
65+
options.loadDefaultStyle = False
66+
return QgsRasterLayer(os.path.join(AlgorithmsTestBase.processingTestDataPath(), 'raster.tif'),
67+
"raster_input",
68+
'gdal',
69+
options)
70+
71+
def test_bug21373_mode_vector(self):
72+
"""
73+
This issue is reported on qgis bug tracker: #21373
74+
This issue is reported on qgis-otb-plugin tracker: #30
75+
"""
76+
context = QgsProcessingContext()
77+
context.setProject(QgsProject.instance())
78+
feedback = QgsProcessingFeedback()
79+
parameters = {
80+
'in': TestOtbAlgorithms.__input_raster_layer(),
81+
'filter': 'meanshift',
82+
'mode.vector.out': 'vector.shp'
83+
}
84+
alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
85+
results = alg.processAlgorithm(parameters, context, feedback)
86+
self.assertDictEqual(results, {'mode.vector.out': 'vector.shp'})
87+
88+
def test_bug21373_mode_raster(self):
89+
"""
90+
This issue is reported on qgis bug tracker: #21373
91+
"""
92+
context = QgsProcessingContext()
93+
context.setProject(QgsProject.instance())
94+
feedback = QgsProcessingFeedback()
95+
parameters = {
96+
'in': TestOtbAlgorithms.__input_raster_layer(),
97+
'filter': 'meanshift',
98+
'mode': 'raster',
99+
'mode.raster.out': 'raster.tif'
100+
}
101+
alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
102+
results = alg.processAlgorithm(parameters, context, feedback)
103+
self.assertDictEqual(results, {'mode.raster.out': 'raster.tif'})
104+
105+
def test_bug21374_Fail(self):
106+
"""
107+
This issue is reported on qgis bug tracker: #21374
108+
"""
109+
outdir = tempfile.mkdtemp()
110+
self.cleanup_paths.append(outdir)
111+
context = QgsProcessingContext()
112+
context.setProject(QgsProject.instance())
113+
feedback = QgsProcessingFeedback()
114+
parameters = {
115+
'in': TestOtbAlgorithms.__input_raster_layer(),
116+
'filter': 'cc',
117+
'mode.vector.out': os.path.join(outdir, 'vector.shp')
118+
}
119+
120+
alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
121+
ok, msg = alg.checkParameterValues(parameters, context)
122+
self.assertFalse(ok, 'Algorithm failed checkParameterValues with result {}'.format(msg))
123+
61124
def test_init_algorithms(self):
62125
"""
63126
This test will read each otb algorithm in 'algs.txt'

0 commit comments

Comments
 (0)