def test_OTBParameterChoiceExists(self): """ This test is here to know if we have change `type()` method of :class: `OtbParameterChoice` That value is used by Otb when it creates descriptor files. So changes to this string must be test in a unit-test. """ alg_smoothing = OtbAlgorithm( 'Image Filtering', 'Smoothing', os.path.join(self.descrFolder, 'Smoothing.txt')) found = False for param in alg_smoothing.parameterDefinitions(): # print (param.name(), param.type()) if param.type() == 'OTBParameterChoice': found = True break self.assertEqual(found, True)
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' and creates an instance of OtbAlgorithm and check if it can be executed This is done in :class: `OtbAlgorithmProvider` load() method """ algs_txt = os.path.join(self.descrFolder, 'algs.txt') with open(algs_txt) as lines: line = lines.readline().strip('\n').strip() if line != '' and line.startswith('#'): version = line[1:] print('version =', version) line = lines.readline().strip('\n').strip() while line != '' and not line.startswith('#'): data = line.split('|') descriptionFile = os.path.join(self.descrFolder, str(data[1]) + '.txt') alg = OtbAlgorithm(data[0], data[1], descriptionFile) self.assertIsInstance(alg, OtbAlgorithm) ret, msg = alg.canExecute() print("canExecute '{}' - {}".format(alg.id(), ret)) self.assertEqual(ret, True) line = lines.readline().strip('\n').strip()