Navigation Menu

Skip to content

Commit

Permalink
[CI] fix travis test for OtbAlgorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Kanavath authored and nyalldawson committed Feb 22, 2019
1 parent e286d5b commit 471865a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .docker/qgis3-build-deps.dockerfile
Expand Up @@ -144,8 +144,9 @@ RUN locale-gen
RUN echo "alias python=python3" >> ~/.bash_aliases

# OTB: download and install otb packages for QGIS tests
RUN curl https://orfeo-toolbox.org/packages/qgis/OTB-Linux64.run -o /tmp/OTB-Linux64.run && sh /tmp/OTB-Linux64.run
ENV OTB_INSTALL_DIR=/tmp/OTB-Linux64
RUN curl -k https://orfeo-toolbox.org/qgis/OTB-Linux64.run -o /tmp/OTB-Linux64.run && sh /tmp/OTB-Linux64.run --target /opt/otb
ENV OTB_INSTALL_DIR=/opt/otb

ENV CC=/usr/lib/ccache/clang
ENV CXX=/usr/lib/ccache/clang++
ENV QT_SELECT=5
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/otb/OtbAlgorithm.py
Expand Up @@ -188,7 +188,7 @@ def preprocessParameters(self, parameters):

return valid_params

def get_value(self, v):
def otbParameterValue(self, v):
if isinstance(v, QgsMapLayer):
return v.source()
elif isinstance(v, QgsProcessingOutputLayerDefinition):
Expand Down Expand Up @@ -222,9 +222,9 @@ def processAlgorithm(self, parameters, context, feedback):
if isinstance(v, list):
value = ''
for i in list(filter(None, v)):
value += '"{}" '.format(self.get_value(i))
value += '"{}" '.format(self.otbParameterValue(i))
else:
value = '"{}"'.format(self.get_value(v))
value = '"{}"'.format(self.otbParameterValue(v))

if k == output_key and 'outputpixeltype' in parameters:
output_pixel_type = self.pixelTypes[int(parameters['outputpixeltype'])]
Expand Down
1 change: 0 additions & 1 deletion python/plugins/processing/algs/otb/OtbUtils.py
Expand Up @@ -83,7 +83,6 @@ def geoidFile():

def executeOtb(command, feedback, addToLog=True):
loglines = []
feedback.setProgress(0)
with subprocess.Popen(
[command],
shell=True,
Expand Down
21 changes: 11 additions & 10 deletions python/plugins/processing/tests/OtbAlgorithmsTest.py
Expand Up @@ -33,6 +33,7 @@
import nose2

from qgis.core import (QgsProcessingParameterNumber,
QgsApplication,
QgsProcessingParameterDefinition)
from qgis.testing import start_app, unittest
#from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
Expand All @@ -43,18 +44,11 @@
from processing.tools import dataobjects
import AlgorithmsTestBase

#export QGIS_DISABLE_MESSAGE_HOOKS=1
#sys.path.append('/home/rashad/projects/qgis/qgis/build/output/python')
#sys.path.append('/home/rashad/projects/qgis/qgis/build/output/python/plugins')
#sys.path.append('/home/rashad/projects/qgis/otb-plugin')

# /home/rashad/projects/otb/gitlab/build"
OTB_INSTALL_DIR = os.environ.get('OTB_INSTALL_DIR')


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

#algList = []
def test_init_algorithms(self):
algs_txt = os.path.join(self.descrFolder, 'algs.txt')
with open(algs_txt) as lines:
Expand All @@ -67,10 +61,11 @@ def test_init_algorithms(self):
data = line.split('|')
descriptionFile = os.path.join(self.descrFolder, str(data[1]) + '.txt')
alg = OtbAlgorithm(data[0], data[1], descriptionFile)
print("Loading Algorithm: '{}' - OK".format(alg.id()))
self.assertIsInstance(alg, OtbAlgorithm)
ret, msg = alg.canExecute()
line = lines.readline().strip('\n').strip()
print("canExecute '{}' - {}".format(alg.id(), ret))
self.assertEqual(ret, True)
line = lines.readline().strip('\n').strip()

def test_choice_parameter_smoothing(self):
alg_smoothing = OtbAlgorithm('Image Filtering', 'Smoothing', os.path.join(self.descrFolder, 'Smoothing.txt'))
Expand All @@ -88,10 +83,15 @@ def setUpClass(cls):
cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description')
from processing.core.Processing import Processing
Processing.initialize()
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR)
ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications'))
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
ProcessingConfig.readSettings()
#refresh OTB Algorithms after settings are changed.
for p in QgsApplication.processingRegistry().providers():
if p.id() == "otb":
p.refreshAlgorithms()

cls.cleanup_paths = []

@classmethod
Expand All @@ -102,6 +102,7 @@ def tearDownClass(cls):
shutil.rmtree(path)

def test_definition_file(self):
print("OTB_INSTALL_DIR = '{}'".format(OTB_INSTALL_DIR))
return 'otb_algorithm_tests.yaml'


Expand Down

0 comments on commit 471865a

Please sign in to comment.