Skip to content

Commit 471865a

Browse files
Rashad Kanavathnyalldawson
authored andcommitted
[CI] fix travis test for OtbAlgorithms
1 parent e286d5b commit 471865a

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

.docker/qgis3-build-deps.dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ RUN locale-gen
144144
RUN echo "alias python=python3" >> ~/.bash_aliases
145145

146146
# OTB: download and install otb packages for QGIS tests
147-
RUN curl https://orfeo-toolbox.org/packages/qgis/OTB-Linux64.run -o /tmp/OTB-Linux64.run && sh /tmp/OTB-Linux64.run
148-
ENV OTB_INSTALL_DIR=/tmp/OTB-Linux64
147+
RUN curl -k https://orfeo-toolbox.org/qgis/OTB-Linux64.run -o /tmp/OTB-Linux64.run && sh /tmp/OTB-Linux64.run --target /opt/otb
148+
ENV OTB_INSTALL_DIR=/opt/otb
149+
149150
ENV CC=/usr/lib/ccache/clang
150151
ENV CXX=/usr/lib/ccache/clang++
151152
ENV QT_SELECT=5

python/plugins/processing/algs/otb/OtbAlgorithm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def preprocessParameters(self, parameters):
188188

189189
return valid_params
190190

191-
def get_value(self, v):
191+
def otbParameterValue(self, v):
192192
if isinstance(v, QgsMapLayer):
193193
return v.source()
194194
elif isinstance(v, QgsProcessingOutputLayerDefinition):
@@ -222,9 +222,9 @@ def processAlgorithm(self, parameters, context, feedback):
222222
if isinstance(v, list):
223223
value = ''
224224
for i in list(filter(None, v)):
225-
value += '"{}" '.format(self.get_value(i))
225+
value += '"{}" '.format(self.otbParameterValue(i))
226226
else:
227-
value = '"{}"'.format(self.get_value(v))
227+
value = '"{}"'.format(self.otbParameterValue(v))
228228

229229
if k == output_key and 'outputpixeltype' in parameters:
230230
output_pixel_type = self.pixelTypes[int(parameters['outputpixeltype'])]

python/plugins/processing/algs/otb/OtbUtils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def geoidFile():
8383

8484
def executeOtb(command, feedback, addToLog=True):
8585
loglines = []
86-
feedback.setProgress(0)
8786
with subprocess.Popen(
8887
[command],
8988
shell=True,

python/plugins/processing/tests/OtbAlgorithmsTest.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import nose2
3434

3535
from qgis.core import (QgsProcessingParameterNumber,
36+
QgsApplication,
3637
QgsProcessingParameterDefinition)
3738
from qgis.testing import start_app, unittest
3839
#from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
@@ -43,18 +44,11 @@
4344
from processing.tools import dataobjects
4445
import AlgorithmsTestBase
4546

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"
5247
OTB_INSTALL_DIR = os.environ.get('OTB_INSTALL_DIR')
5348

5449

5550
class TestOtbAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
5651

57-
#algList = []
5852
def test_init_algorithms(self):
5953
algs_txt = os.path.join(self.descrFolder, 'algs.txt')
6054
with open(algs_txt) as lines:
@@ -67,10 +61,11 @@ def test_init_algorithms(self):
6761
data = line.split('|')
6862
descriptionFile = os.path.join(self.descrFolder, str(data[1]) + '.txt')
6963
alg = OtbAlgorithm(data[0], data[1], descriptionFile)
70-
print("Loading Algorithm: '{}' - OK".format(alg.id()))
64+
self.assertIsInstance(alg, OtbAlgorithm)
7165
ret, msg = alg.canExecute()
72-
line = lines.readline().strip('\n').strip()
66+
print("canExecute '{}' - {}".format(alg.id(), ret))
7367
self.assertEqual(ret, True)
68+
line = lines.readline().strip('\n').strip()
7469

7570
def test_choice_parameter_smoothing(self):
7671
alg_smoothing = OtbAlgorithm('Image Filtering', 'Smoothing', os.path.join(self.descrFolder, 'Smoothing.txt'))
@@ -88,10 +83,15 @@ def setUpClass(cls):
8883
cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description')
8984
from processing.core.Processing import Processing
9085
Processing.initialize()
86+
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
9187
ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR)
9288
ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications'))
93-
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
9489
ProcessingConfig.readSettings()
90+
#refresh OTB Algorithms after settings are changed.
91+
for p in QgsApplication.processingRegistry().providers():
92+
if p.id() == "otb":
93+
p.refreshAlgorithms()
94+
9595
cls.cleanup_paths = []
9696

9797
@classmethod
@@ -102,6 +102,7 @@ def tearDownClass(cls):
102102
shutil.rmtree(path)
103103

104104
def test_definition_file(self):
105+
print("OTB_INSTALL_DIR = '{}'".format(OTB_INSTALL_DIR))
105106
return 'otb_algorithm_tests.yaml'
106107

107108

0 commit comments

Comments
 (0)