Skip to content

Commit 30bcfeb

Browse files
Rashad Kanavathnyalldawson
Rashad Kanavath
authored andcommittedFeb 22, 2019
[TEST] add test for OTB processing provider
This includes yaml test like SAGA, GRASS and also test for loading OTB Algorithms
1 parent 3b87f7b commit 30bcfeb

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed
 

‎python/plugins/processing/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ IF(ENABLE_TESTS)
1717
ADD_PYTHON_TEST(ProcessingGrass7AlgorithmsImageryTest Grass7AlgorithmsImageryTest.py)
1818
ADD_PYTHON_TEST(ProcessingGrass7AlgorithmsRasterTest Grass7AlgorithmsRasterTest.py)
1919
ADD_PYTHON_TEST(ProcessingGrass7AlgorithmsVectorTest Grass7AlgorithmsVectorTest.py)
20+
ADD_PYTHON_TEST(ProcessingOtbAlgorithmsTest OtbAlgorithmsTest.py)
2021
ADD_PYTHON_TEST(ProcessingSagaAlgorithmsTest SagaAlgorithmsTest.py)
2122
ADD_PYTHON_TEST(ProcessingCheckValidityAlgorithmTest CheckValidityAlgorithm.py)
2223
ENDIF(ENABLE_TESTS)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# See ../README.md for a description of the file format
2+
3+
tests:
4+
- algorithm: otb:Smoothing
5+
name: Test (otb:Smoothing anidif)
6+
params:
7+
in:
8+
name: raster.tif
9+
type: file
10+
type: anidif
11+
type.anidif.conductance: 2.0
12+
type.anidif.nbiter: 10
13+
type.anidif.timestep: 0.125
14+
results:
15+
out:
16+
hash: 481539d39d92ed9a63c493235a4696be79d82f25608f190ddedb4cdf
17+
type: rasterhash
18+
19+
- algorithm: otb:Smoothing
20+
name: Test (otb:Smoothing mean)
21+
params:
22+
in:
23+
name: raster.tif
24+
type: file
25+
type: gaussian
26+
type.gaussian.radius: 4.0
27+
results:
28+
out:
29+
hash: b3fbccd6f41052317a435567a2633dae1d9b66772a4d8a3323d9b1c5
30+
type: rasterhash
31+
32+
- algorithm: otb:HaralickTextureExtraction
33+
name: Test (otb:HaralickTextureExtraction)
34+
params:
35+
channel: 1
36+
in:
37+
name: raster with spaces.tif
38+
type: file
39+
parameters.max: 255.0
40+
parameters.min: 0.0
41+
parameters.nbbin: 8
42+
parameters.xoff: 1
43+
parameters.xrad: 2
44+
parameters.yoff: 1
45+
parameters.yrad: 2
46+
step: 1
47+
texture: simple
48+
results:
49+
out:
50+
hash: 3132281993d8474d5404f01fb5afa68c9648c282da5546823281cc1c
51+
type: rasterhash
52+

0 commit comments

Comments
 (0)
Please sign in to comment.