|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + OtbAlgorithmsTests.py |
| 6 | + --------------------- |
| 7 | + Date : January 2019 |
| 8 | + Copyright : (C) 2019 by CNES |
| 9 | + Author : otb att cnes dot fr |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Rashad Kanavath' |
| 21 | +__date__ = 'Janauary 2019' |
| 22 | +__copyright__ = '(C) 2019, CNES' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = ':%H$' |
| 27 | + |
| 28 | +import os |
| 29 | +import sys |
| 30 | +import unittest |
| 31 | +import hashlib |
| 32 | +import shutil |
| 33 | +import nose2 |
| 34 | + |
| 35 | +from qgis.core import (QgsProcessingParameterNumber, |
| 36 | + QgsProcessingParameterDefinition) |
| 37 | +from qgis.testing import start_app, unittest |
| 38 | +#from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice |
| 39 | +from processing.algs.otb.OtbAlgorithm import OtbAlgorithm |
| 40 | +from processing.algs.otb.OtbAlgorithmProvider import OtbAlgorithmProvider |
| 41 | +from processing.algs.otb.OtbSettings import OtbSettings |
| 42 | +from processing.core.ProcessingConfig import ProcessingConfig, Setting |
| 43 | +from processing.tools import dataobjects |
| 44 | +import AlgorithmsTestBase |
| 45 | + |
| 46 | +#export QGIS_DISABLE_MESSAGE_HOOKS=1 |
| 47 | +#sys.path.append('/home/rashad/projects/qgis/qgis/build/output/python') |
| 48 | +#sys.path.append('/home/rashad/projects/qgis/qgis/build/output/python/plugins') |
| 49 | +#sys.path.append('/home/rashad/projects/qgis/otb-plugin') |
| 50 | + |
| 51 | +# /home/rashad/projects/otb/gitlab/build" |
| 52 | +OTB_INSTALL_DIR = os.environ.get('OTB_INSTALL_DIR') |
| 53 | + |
| 54 | + |
| 55 | +class TestOtbAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest): |
| 56 | + |
| 57 | + #algList = [] |
| 58 | + def test_init_algorithms(self): |
| 59 | + algs_txt = os.path.join(self.descrFolder, 'algs.txt') |
| 60 | + with open(algs_txt) as lines: |
| 61 | + line = lines.readline().strip('\n').strip() |
| 62 | + if line != '' and line.startswith('#'): |
| 63 | + version = line[1:] |
| 64 | + print('version =', version) |
| 65 | + line = lines.readline().strip('\n').strip() |
| 66 | + while line != '' and not line.startswith('#'): |
| 67 | + data = line.split('|') |
| 68 | + descriptionFile = os.path.join(self.descrFolder, str(data[1]) + '.txt') |
| 69 | + alg = OtbAlgorithm(data[0], data[1], descriptionFile) |
| 70 | + print("Loading Algorithm: '{}' - OK".format(alg.id())) |
| 71 | + ret, msg = alg.canExecute() |
| 72 | + line = lines.readline().strip('\n').strip() |
| 73 | + self.assertEqual(ret, True) |
| 74 | + |
| 75 | + def test_choice_parameter_smoothing(self): |
| 76 | + alg_smoothing = OtbAlgorithm('Image Filtering', 'Smoothing', os.path.join(self.descrFolder, 'Smoothing.txt')) |
| 77 | + found = False |
| 78 | + for param in alg_smoothing.parameterDefinitions(): |
| 79 | + ## print (param.name(), param.type()) |
| 80 | + if param.type() == 'OTBParameterChoice': |
| 81 | + found = True |
| 82 | + break |
| 83 | + self.assertEqual(found, True) |
| 84 | + |
| 85 | + @classmethod |
| 86 | + def setUpClass(cls): |
| 87 | + start_app() |
| 88 | + cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description') |
| 89 | + from processing.core.Processing import Processing |
| 90 | + Processing.initialize() |
| 91 | + ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR) |
| 92 | + ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications')) |
| 93 | + ProcessingConfig.setSettingValue("OTB_ACTIVATE", True) |
| 94 | + ProcessingConfig.readSettings() |
| 95 | + cls.cleanup_paths = [] |
| 96 | + |
| 97 | + @classmethod |
| 98 | + def tearDownClass(cls): |
| 99 | + from processing.core.Processing import Processing |
| 100 | + Processing.deinitialize() |
| 101 | + for path in cls.cleanup_paths: |
| 102 | + shutil.rmtree(path) |
| 103 | + |
| 104 | + def test_definition_file(self): |
| 105 | + return 'otb_algorithm_tests.yaml' |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == '__main__': |
| 109 | + nose2.main() |
0 commit comments