Skip to content

Commit

Permalink
[sextante] modeler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Mar 28, 2013
1 parent 1c0f6c6 commit bfada31
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions python/plugins/sextante/modeler/ModelerAlgorithm.py
Expand Up @@ -212,6 +212,7 @@ def updateAlgorithm(self, algIndex, parametersMap, valuesMap, outputsMap, depend


def removeAlgorithm(self, index):
'''returns true if the algorithm could be removed, false if others depend on it and could not be removed'''
if self.hasDependencies(self.algs[index], index):
return False
for out in self.algs[index].outputs:
Expand Down Expand Up @@ -241,6 +242,7 @@ def removeAlgorithm(self, index):
return True

def removeParameter(self, index):
'''returns true if the parameter could be removed, false if others depend on it and could not be removed'''
if self.hasDependencies(self.parameters[index], index):
return False
del self.parameters[index]
Expand Down
25 changes: 25 additions & 0 deletions python/plugins/sextante/modeler/models/noinputs.model
@@ -0,0 +1,25 @@
NAME:A model with no parameters
GROUP:[Test models]
VALUE:HARDCODEDPARAMVALUE_HSPACING_0===10
VALUE:HARDCODEDPARAMVALUE_CENTERY_0===0
VALUE:HARDCODEDPARAMVALUE_WIDTH_0===30
VALUE:HARDCODEDPARAMVALUE_GRIDTYPE_0===1
VALUE:HARDCODEDPARAMVALUE_CENTERX_0===0
VALUE:HARDCODEDPARAMVALUE_HEIGHT_0===30
VALUE:HARDCODEDPARAMVALUE_VSPACING_0===10
ALGORITHM:qgis:creategrid
112.0,53.0
None
-1|HARDCODEDPARAMVALUE_HSPACING_0
-1|HARDCODEDPARAMVALUE_VSPACING_0
-1|HARDCODEDPARAMVALUE_WIDTH_0
-1|HARDCODEDPARAMVALUE_HEIGHT_0
-1|HARDCODEDPARAMVALUE_CENTERX_0
-1|HARDCODEDPARAMVALUE_CENTERY_0
-1|HARDCODEDPARAMVALUE_GRIDTYPE_0
grid
ALGORITHM:qgis:polygoncentroids
109.0,195.0
None
0|SAVENAME
centroids
3 changes: 3 additions & 0 deletions python/plugins/sextante/script/scripts/Load_test_data.py
@@ -0,0 +1,3 @@
##[Example scripts]=group

sextante.loadTestData()
26 changes: 22 additions & 4 deletions python/plugins/sextante/tests/ModelerAlgorithmTest.py
Expand Up @@ -6,18 +6,36 @@
import os
from osgeo import gdal
from osgeo.gdalconst import GA_ReadOnly
from sextante.modeler import ModelerAlgorithmProvider
from sextante.modeler.ModelerAlgorithm import ModelerAlgorithm


class ModelerAlgorithmTest(unittest.TestCase):

def testCreateModel(self):
pass

def testRemoveParameter(self):
pass

def testRemoveAlgorithm(self):
pass
'''NOTE:this is not passing, since the algCopy method reload from file'''
folder = os.path.join(os.path.dirname(ModelerAlgorithmProvider.__file__), "models")
modelfile = os.path.join(folder, "noinputs.model")
model = ModelerAlgorithm()
model.openModel(modelfile)
self.assertTrue(2, len(model.algs))
self.assertFalse(model.removeAlgorithm(0))
self.assertTrue(model.removeAlgorithm(len(model.algs) - 1));
outputs = sextante.runalg(model, None)
self.assertEquals(2, len(outputs))
output=outputs['SAVENAME_ALG0']
layer=QGisLayers.getObjectFromUri(output, True)
self.assertIsNone(layer)

def testRemoveParameter(self):
pass



'''The following tests correspond to example models'''

def test_modelersagagrass(self):
outputs=sextante.runalg("modeler:sagagrass",points(),None)
Expand Down

0 comments on commit bfada31

Please sign in to comment.