Skip to content
Permalink
Browse files

[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.
  • Loading branch information
rkanavath authored and nyalldawson committed Mar 18, 2019
1 parent 0b86110 commit e94d9a596ab167b16b90098bbf2541b3659413b3
Showing with 63 additions and 0 deletions.
  1. +63 −0 python/plugins/processing/tests/OtbAlgorithmsTest.py
@@ -34,6 +34,7 @@
import tempfile
from qgis.core import (QgsProcessingParameterNumber,
QgsApplication,
QgsRasterLayer,
QgsMapLayer,
QgsProject,
QgsProcessingContext,
@@ -58,6 +59,68 @@

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

@staticmethod
def __input_raster_layer():
options = QgsRasterLayer.LayerOptions()
options.loadDefaultStyle = False
return QgsRasterLayer(os.path.join(AlgorithmsTestBase.processingTestDataPath(), 'raster.tif'),
"raster_input",
'gdal',
options)

def test_bug21373_mode_vector(self):
"""
This issue is reported on qgis bug tracker: #21373
This issue is reported on qgis-otb-plugin tracker: #30
"""
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
feedback = QgsProcessingFeedback()
parameters = {
'in': TestOtbAlgorithms.__input_raster_layer(),
'filter': 'meanshift',
'mode.vector.out': 'vector.shp'
}
alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
results = alg.processAlgorithm(parameters, context, feedback)
self.assertDictEqual(results, {'mode.vector.out': 'vector.shp'})

def test_bug21373_mode_raster(self):
"""
This issue is reported on qgis bug tracker: #21373
"""
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
feedback = QgsProcessingFeedback()
parameters = {
'in': TestOtbAlgorithms.__input_raster_layer(),
'filter': 'meanshift',
'mode': 'raster',
'mode.raster.out': 'raster.tif'
}
alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
results = alg.processAlgorithm(parameters, context, feedback)
self.assertDictEqual(results, {'mode.raster.out': 'raster.tif'})

def test_bug21374_Fail(self):
"""
This issue is reported on qgis bug tracker: #21374
"""
outdir = tempfile.mkdtemp()
self.cleanup_paths.append(outdir)
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
feedback = QgsProcessingFeedback()
parameters = {
'in': TestOtbAlgorithms.__input_raster_layer(),
'filter': 'cc',
'mode.vector.out': os.path.join(outdir, 'vector.shp')
}

alg = OtbAlgorithm('Segmentation', 'Segmentation', os.path.join(self.descrFolder, 'Segmentation.txt'))
ok, msg = alg.checkParameterValues(parameters, context)
self.assertFalse(ok, 'Algorithm failed checkParameterValues with result {}'.format(msg))

def test_init_algorithms(self):
"""
This test will read each otb algorithm in 'algs.txt'

0 comments on commit e94d9a5

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