2
2
3
3
"""
4
4
***************************************************************************
5
- OtbAlgorithmsTests .py
5
+ OtbAlgorithmsTest .py
6
6
---------------------
7
7
Date : January 2019
8
8
Copyright : (C) 2019 by CNES
31
31
import hashlib
32
32
import shutil
33
33
import nose2
34
-
35
34
from qgis .core import (QgsProcessingParameterNumber ,
36
35
QgsApplication ,
37
36
QgsProcessingParameterDefinition )
38
37
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
40
43
from processing .algs .otb .OtbAlgorithm import OtbAlgorithm
41
44
from processing .algs .otb .OtbAlgorithmProvider import OtbAlgorithmProvider
42
45
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
45
47
import AlgorithmsTestBase
46
48
47
49
OTB_INSTALL_DIR = os .environ .get ('OTB_INSTALL_DIR' )
@@ -67,7 +69,7 @@ def test_init_algorithms(self):
67
69
self .assertEqual (ret , True )
68
70
line = lines .readline ().strip ('\n ' ).strip ()
69
71
70
- def test_choice_parameter_smoothing (self ):
72
+ def test_OTBParameterChoice (self ):
71
73
alg_smoothing = OtbAlgorithm ('Image Filtering' , 'Smoothing' , os .path .join (self .descrFolder , 'Smoothing.txt' ))
72
74
found = False
73
75
for param in alg_smoothing .parameterDefinitions ():
@@ -77,21 +79,51 @@ def test_choice_parameter_smoothing(self):
77
79
break
78
80
self .assertEqual (found , True )
79
81
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
+
80
113
@classmethod
81
114
def setUpClass (cls ):
82
115
start_app ()
83
- cls .descrFolder = os .path .join (OTB_INSTALL_DIR , 'share' , 'otb' , 'description' )
84
116
from processing .core .Processing import Processing
85
117
Processing .initialize ()
86
118
ProcessingConfig .setSettingValue ("OTB_ACTIVATE" , True )
87
119
ProcessingConfig .setSettingValue (OtbSettings .FOLDER , OTB_INSTALL_DIR )
88
120
ProcessingConfig .setSettingValue (OtbSettings .APP_FOLDER , os .path .join (OTB_INSTALL_DIR , 'lib' , 'otb' , 'applications' ))
89
121
ProcessingConfig .readSettings ()
90
- #refresh OTB Algorithms after settings are changed.
122
+ # Refresh OTB Algorithms after settings are changed.
91
123
for p in QgsApplication .processingRegistry ().providers ():
92
124
if p .id () == "otb" :
93
125
p .refreshAlgorithms ()
94
-
126
+ cls . descrFolder = os . path . join ( OTB_INSTALL_DIR , 'share' , 'otb' , 'description' )
95
127
cls .cleanup_paths = []
96
128
97
129
@classmethod
0 commit comments