Skip to content

Commit 8afb80e

Browse files
Rashad Kanavathnyalldawson
Rashad Kanavath
authored andcommitted
[test] new test for OtbChoiceWidget
This can easily go into GuiTests.py but we tend to keep it out due to usage of create_from_metadata(). All widget in GuiTests uses create_from_class() which will not work for this special widget
1 parent e26e098 commit 8afb80e

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

python/plugins/processing/tests/OtbAlgorithmsTest.py

+41-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""
44
***************************************************************************
5-
OtbAlgorithmsTests.py
5+
OtbAlgorithmsTest.py
66
---------------------
77
Date : January 2019
88
Copyright : (C) 2019 by CNES
@@ -31,17 +31,19 @@
3131
import hashlib
3232
import shutil
3333
import nose2
34-
3534
from qgis.core import (QgsProcessingParameterNumber,
3635
QgsApplication,
3736
QgsProcessingParameterDefinition)
3837
from qgis.testing import start_app, unittest
39-
#from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
38+
from processing.core.ProcessingConfig import ProcessingConfig, Setting
39+
from processing.gui.AlgorithmDialog import AlgorithmDialog
40+
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
41+
from processing.gui.wrappers import *
42+
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
4043
from processing.algs.otb.OtbAlgorithm import OtbAlgorithm
4144
from processing.algs.otb.OtbAlgorithmProvider import OtbAlgorithmProvider
4245
from processing.algs.otb.OtbSettings import OtbSettings
43-
from processing.core.ProcessingConfig import ProcessingConfig, Setting
44-
from processing.tools import dataobjects
46+
from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice, OtbChoiceWidgetWrapper
4547
import AlgorithmsTestBase
4648

4749
OTB_INSTALL_DIR = os.environ.get('OTB_INSTALL_DIR')
@@ -67,7 +69,7 @@ def test_init_algorithms(self):
6769
self.assertEqual(ret, True)
6870
line = lines.readline().strip('\n').strip()
6971

70-
def test_choice_parameter_smoothing(self):
72+
def test_OTBParameterChoice(self):
7173
alg_smoothing = OtbAlgorithm('Image Filtering', 'Smoothing', os.path.join(self.descrFolder, 'Smoothing.txt'))
7274
found = False
7375
for param in alg_smoothing.parameterDefinitions():
@@ -77,21 +79,51 @@ def test_choice_parameter_smoothing(self):
7779
break
7880
self.assertEqual(found, True)
7981

82+
def test_OTBParameterChoice_Gui(self):
83+
param = OtbParameterChoice('test')
84+
85+
alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing')
86+
# algorithm dialog
87+
dlg = AlgorithmDialog(alg)
88+
wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg)
89+
self.assertIsNotNone(wrapper)
90+
self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper)
91+
self.assertEqual(wrapper.dialog, dlg)
92+
self.assertIsNotNone(wrapper.widget)
93+
94+
alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing')
95+
# batch dialog
96+
dlg = BatchAlgorithmDialog(alg)
97+
wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg)
98+
self.assertIsNotNone(wrapper)
99+
self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper)
100+
self.assertEqual(wrapper.dialog, dlg)
101+
self.assertIsNotNone(wrapper.widget)
102+
103+
alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing')
104+
# modeler dialog
105+
model = QgsProcessingModelAlgorithm()
106+
dlg = ModelerParametersDialog(alg, model)
107+
wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg)
108+
self.assertIsNotNone(wrapper)
109+
self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper)
110+
self.assertEqual(wrapper.dialog, dlg)
111+
self.assertIsNotNone(wrapper.widget)
112+
80113
@classmethod
81114
def setUpClass(cls):
82115
start_app()
83-
cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description')
84116
from processing.core.Processing import Processing
85117
Processing.initialize()
86118
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
87119
ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR)
88120
ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications'))
89121
ProcessingConfig.readSettings()
90-
#refresh OTB Algorithms after settings are changed.
122+
# Refresh OTB Algorithms after settings are changed.
91123
for p in QgsApplication.processingRegistry().providers():
92124
if p.id() == "otb":
93125
p.refreshAlgorithms()
94-
126+
cls.descrFolder = os.path.join(OTB_INSTALL_DIR, 'share', 'otb', 'description')
95127
cls.cleanup_paths = []
96128

97129
@classmethod

0 commit comments

Comments
 (0)