33
33
import nose2
34
34
35
35
from qgis .core import (QgsProcessingParameterNumber ,
36
+ QgsApplication ,
36
37
QgsProcessingParameterDefinition )
37
38
from qgis .testing import start_app , unittest
38
39
#from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice
43
44
from processing .tools import dataobjects
44
45
import AlgorithmsTestBase
45
46
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
47
OTB_INSTALL_DIR = os .environ .get ('OTB_INSTALL_DIR' )
53
48
54
49
55
50
class TestOtbAlgorithms (unittest .TestCase , AlgorithmsTestBase .AlgorithmsTest ):
56
51
57
- #algList = []
58
52
def test_init_algorithms (self ):
59
53
algs_txt = os .path .join (self .descrFolder , 'algs.txt' )
60
54
with open (algs_txt ) as lines :
@@ -67,10 +61,11 @@ def test_init_algorithms(self):
67
61
data = line .split ('|' )
68
62
descriptionFile = os .path .join (self .descrFolder , str (data [1 ]) + '.txt' )
69
63
alg = OtbAlgorithm (data [0 ], data [1 ], descriptionFile )
70
- print ( "Loading Algorithm: '{}' - OK" . format (alg . id ()) )
64
+ self . assertIsInstance (alg , OtbAlgorithm )
71
65
ret , msg = alg .canExecute ()
72
- line = lines . readline (). strip ( ' \n ' ). strip ( )
66
+ print ( "canExecute '{}' - {}" . format ( alg . id (), ret ) )
73
67
self .assertEqual (ret , True )
68
+ line = lines .readline ().strip ('\n ' ).strip ()
74
69
75
70
def test_choice_parameter_smoothing (self ):
76
71
alg_smoothing = OtbAlgorithm ('Image Filtering' , 'Smoothing' , os .path .join (self .descrFolder , 'Smoothing.txt' ))
@@ -88,10 +83,15 @@ def setUpClass(cls):
88
83
cls .descrFolder = os .path .join (OTB_INSTALL_DIR , 'share' , 'otb' , 'description' )
89
84
from processing .core .Processing import Processing
90
85
Processing .initialize ()
86
+ ProcessingConfig .setSettingValue ("OTB_ACTIVATE" , True )
91
87
ProcessingConfig .setSettingValue (OtbSettings .FOLDER , OTB_INSTALL_DIR )
92
88
ProcessingConfig .setSettingValue (OtbSettings .APP_FOLDER , os .path .join (OTB_INSTALL_DIR , 'lib' , 'otb' , 'applications' ))
93
- ProcessingConfig .setSettingValue ("OTB_ACTIVATE" , True )
94
89
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
+
95
95
cls .cleanup_paths = []
96
96
97
97
@classmethod
@@ -102,6 +102,7 @@ def tearDownClass(cls):
102
102
shutil .rmtree (path )
103
103
104
104
def test_definition_file (self ):
105
+ print ("OTB_INSTALL_DIR = '{}'" .format (OTB_INSTALL_DIR ))
105
106
return 'otb_algorithm_tests.yaml'
106
107
107
108
0 commit comments