Skip to content

Commit

Permalink
[processing] check for parent alg dependencies in hasDependencies()
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 11, 2016
1 parent 156fce9 commit be2223f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ def hasDependencies(self, name):
elif isinstance(value, ValueFromOutput):
if value.alg == name:
return True
if alg.name != name:
for dep in alg.dependencies:
if (dep == name):
return True
return False

def getDependsOnAlgorithms(self, name):
Expand Down
26 changes: 25 additions & 1 deletion python/plugins/processing/tests/ModelerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

from qgis.testing import start_app, unittest

from processing.modeler.ModelerAlgorithm import (ModelerAlgorithm, ModelerParameter)
from processing.modeler.ModelerAlgorithm import (Algorithm,
ModelerAlgorithm,
ModelerParameter,
ModelerOutput,
ValueFromOutput)
from processing.modeler.ModelerParametersDialog import (ModelerParametersDialog)
from processing.core.parameters import (ParameterFile,
ParameterNumber,
Expand Down Expand Up @@ -66,6 +70,26 @@ def testModelerParametersDialogAvailableValuesOfType(self):
self.assertEqual(set(p.name for p in dlg.getAvailableValuesOfType([ParameterString, ParameterNumber, ParameterFile])),
set(['string', 'string2', 'number', 'file']))

def testModelerAlgorithmHasDependencies(self):
# test hasDependencies from ModelerAlgorithm

m = ModelerAlgorithm()

a = Algorithm("qgis:clip")
m.addAlgorithm(a)
a2 = Algorithm("qgis:clip")
m.addAlgorithm(a2)

# test parent algorithm dependency
self.assertEqual(m.hasDependencies('QGISCLIP_1'), False)
a2.dependencies = ['QGISCLIP_1']
self.assertEqual(m.hasDependencies('QGISCLIP_1'), True)

# test output algorithm dependency
a2.dependencies = []
a.outputs['OUTPUT'] = ModelerOutput('out')
a2.params['INPUT'] = ValueFromOutput('QGISCLIP_1', 'OUTPUT')
self.assertEqual(m.hasDependencies('QGISCLIP_1'), True)

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

0 comments on commit be2223f

Please sign in to comment.