|
34 | 34 | import tempfile
|
35 | 35 | from qgis.core import (QgsProcessingParameterNumber,
|
36 | 36 | QgsApplication,
|
| 37 | + QgsRasterLayer, |
37 | 38 | QgsMapLayer,
|
38 | 39 | QgsProject,
|
39 | 40 | QgsProcessingContext,
|
|
58 | 59 |
|
59 | 60 | class TestOtbAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
60 | 61 |
|
| 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 | + |
61 | 124 | def test_init_algorithms(self):
|
62 | 125 | """
|
63 | 126 | This test will read each otb algorithm in 'algs.txt'
|
|
0 commit comments