Skip to content

Commit

Permalink
[TEST] add more test on otb segmentation apps
Browse files Browse the repository at this point in the history
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
Rashad Kanavath authored and nyalldawson committed Mar 20, 2019
1 parent 0b86110 commit e94d9a5
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions python/plugins/processing/tests/OtbAlgorithmsTest.py
Expand Up @@ -34,6 +34,7 @@
import tempfile
from qgis.core import (QgsProcessingParameterNumber,
QgsApplication,
QgsRasterLayer,
QgsMapLayer,
QgsProject,
QgsProcessingContext,
Expand All @@ -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'
Expand Down

0 comments on commit e94d9a5

Please sign in to comment.