1717
1818from qgis .core import (
1919 QgsTask ,
20- QgsTaskManager
20+ QgsTaskManager ,
21+ QgsApplication
2122)
2223from qgis .PyQt .QtCore import (QCoreApplication )
2324
@@ -91,7 +92,7 @@ def testTaskFromFunction(self):
9192 """ test creating task from function """
9293
9394 task = QgsTask .fromFunction ('test task' , run , 20 )
94- QgsTaskManager . instance ().addTask (task )
95+ QgsApplication . taskManager ().addTask (task )
9596 while task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
9697 pass
9798
@@ -101,7 +102,7 @@ def testTaskFromFunction(self):
101102
102103 # try a task which cancels itself
103104 bad_task = QgsTask .fromFunction ('test task2' , run , None )
104- QgsTaskManager . instance ().addTask (bad_task )
105+ QgsApplication . taskManager ().addTask (bad_task )
105106 while bad_task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
106107 pass
107108
@@ -113,7 +114,7 @@ def testTaskFromFunctionWithKwargs(self):
113114 """ test creating task from function using kwargs """
114115
115116 task = QgsTask .fromFunction ('test task3' , run_with_kwargs , result = 5 , password = 1 )
116- QgsTaskManager . instance ().addTask (task )
117+ QgsApplication . taskManager ().addTask (task )
117118 while task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
118119 pass
119120
@@ -124,14 +125,14 @@ def testTaskFromFunctionWithKwargs(self):
124125 def testTaskFromFunctionIsCancellable (self ):
125126 """ test that task from function can check cancelled status """
126127 bad_task = QgsTask .fromFunction ('test task4' , cancellable )
127- QgsTaskManager . instance ().addTask (bad_task )
128+ QgsApplication . taskManager ().addTask (bad_task )
128129 while bad_task .status () != QgsTask .Running :
129130 pass
130131
131132 bad_task .cancel ()
132133 while bad_task .status () == QgsTask .Running :
133134 pass
134- while QgsTaskManager . instance ().countActiveTasks () > 0 :
135+ while QgsApplication . taskManager ().countActiveTasks () > 0 :
135136 QCoreApplication .processEvents ()
136137
137138 self .assertEqual (bad_task .status (), QgsTask .Terminated )
@@ -140,7 +141,7 @@ def testTaskFromFunctionIsCancellable(self):
140141 def testTaskFromFunctionCanSetProgress (self ):
141142 """ test that task from function can set progress """
142143 task = QgsTask .fromFunction ('test task5' , progress_function )
143- QgsTaskManager . instance ().addTask (task )
144+ QgsApplication . taskManager ().addTask (task )
144145 while task .status () != QgsTask .Running :
145146 pass
146147
@@ -152,16 +153,16 @@ def testTaskFromFunctionCanSetProgress(self):
152153 task .cancel ()
153154 while task .status () == QgsTask .Running :
154155 pass
155- while QgsTaskManager . instance ().countActiveTasks () > 0 :
156+ while QgsApplication . taskManager ().countActiveTasks () > 0 :
156157 QCoreApplication .processEvents ()
157158
158159 def testTaskFromFunctionFinished (self ):
159160 """ test that task from function can have callback finished function"""
160161 task = QgsTask .fromFunction ('test task' , run_no_result , on_finished = finished_no_val )
161- QgsTaskManager . instance ().addTask (task )
162+ QgsApplication . taskManager ().addTask (task )
162163 while task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
163164 pass
164- while QgsTaskManager . instance ().countActiveTasks () > 0 :
165+ while QgsApplication . taskManager ().countActiveTasks () > 0 :
165166 QCoreApplication .processEvents ()
166167
167168 # check that the finished function was called
@@ -172,10 +173,10 @@ def testTaskFromFunctionFinished(self):
172173 def testTaskFromFunctionFinishedWithVal (self ):
173174 """ test that task from function can have callback finished function and is passed result values"""
174175 task = QgsTask .fromFunction ('test task' , run_single_val_result , on_finished = finished_single_value_result )
175- QgsTaskManager . instance ().addTask (task )
176+ QgsApplication . taskManager ().addTask (task )
176177 while task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
177178 pass
178- while QgsTaskManager . instance ().countActiveTasks () > 0 :
179+ while QgsApplication . taskManager ().countActiveTasks () > 0 :
179180 QCoreApplication .processEvents ()
180181
181182 # check that the finished function was called
@@ -186,10 +187,10 @@ def testTaskFromFunctionFinishedWithVal(self):
186187 def testTaskFromFunctionFinishedWithMultipleValues (self ):
187188 """ test that task from function can have callback finished function and is passed multiple result values"""
188189 task = QgsTask .fromFunction ('test task' , run_multiple_val_result , on_finished = finished_multiple_value_result )
189- QgsTaskManager . instance ().addTask (task )
190+ QgsApplication . taskManager ().addTask (task )
190191 while task .status () not in [QgsTask .Complete , QgsTask .Terminated ]:
191192 pass
192- while QgsTaskManager . instance ().countActiveTasks () > 0 :
193+ while QgsApplication . taskManager ().countActiveTasks () > 0 :
193194 QCoreApplication .processEvents ()
194195
195196 # check that the finished function was called
0 commit comments