Skip to content

Commit

Permalink
[test] Add ParentDependsOnSubTask subtask test case
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Sep 1, 2018
1 parent ba4fb65 commit 4ad0bbb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/src/python/test_qgstaskmanager.py
Expand Up @@ -17,6 +17,7 @@
from qgis.core import QgsTask, QgsApplication

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtTest import QSignalSpy

from qgis.testing import start_app, unittest
from time import sleep
Expand Down Expand Up @@ -261,6 +262,36 @@ def finished_multiple_value_result(e, results):
self.assertEqual(result_value, 5)
self.assertEqual(result_statement, 'whoo')

def testTaskFromFunctionWithSubTaskCompletedIsCalledOnce(self):
""" test that when a parent task has subtasks it does emit taskCompleted only once"""

self.finished = 0
self.completed = 0

def _on_finished():
self.finished += 1

def _on_completed():
self.completed += 1

task = QgsTask.fromFunction('test task', run_no_result, on_finished=_on_finished)
task.taskCompleted.connect(_on_completed)
spy = QSignalSpy(task.taskCompleted)
sub_task_1 = QgsTask.fromFunction('test subtask 1', run_no_result, on_finished=_on_finished)
sub_task_2 = QgsTask.fromFunction('test subtask 2', run_no_result, on_finished=_on_finished)
task.addSubTask(sub_task_1, [], QgsTask.ParentDependsOnSubTask)
task.addSubTask(sub_task_2, [], QgsTask.ParentDependsOnSubTask)

QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()

self.assertEqual(self.completed, 1)
self.assertEqual(self.finished, 3)
self.assertEqual(len(spy), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4ad0bbb

Please sign in to comment.