Skip to content
Permalink
Browse files

[sextante] Tests stuff. Added new test models and scripts, geojson te…

…stdata and extra tests
  • Loading branch information
volaya committed Mar 28, 2013
1 parent 1f812af commit ea6573a75faf9bf4c190514ede359cf66b88a6a9
@@ -54,11 +54,12 @@ def createTest(text):
i = -1 * len(alg.outputs)
for out in alg.outputs:
filename = tokens[i][1:-1]
if (filename == str(None)):
raise Exception("Cannot create unit test for that algorithm execution.\nThe output cannot be a temporary file")
if (tokens[i] == str(None)):
QtGui.QMessageBox.critical(None, "Error", "Cannot create unit test for that algorithm execution.\nThe output cannot be a temporary file")
return
s+="\toutput=outputs['" + out.name + "']\n"
if isinstance(out, (OutputNumber, OutputString)):
s+="self.assertTrue(" + str(out) + ", output)\n"
s+="self.assertTrue(" + str(out) + ", output.value)\n"
if isinstance(out, OutputRaster):
dataset = gdal.Open(filename, GA_ReadOnly)
strhash = hash(str(dataset.ReadAsArray(0).tolist()))
@@ -16,12 +16,14 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import traceback
import copy
import os.path
import codecs
@@ -121,7 +123,7 @@ def openModel(self, filename):
if param:
self.parameters.append(param)
else:
raise WrongModelException("Error in line: " + line)
raise WrongModelException("Error in parameter line: " + line)
line = lines.readline().strip("\n")
tokens = line.split(",")
self.paramPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
@@ -138,7 +140,7 @@ def openModel(self, filename):
algOutputs={}
algLine = line[len("ALGORITHM:"):]
alg = ModelerUtils.getAlgorithm(algLine)
if alg:
if alg is not None:
posline = lines.readline().strip("\n")
tokens = posline.split(",")
self.algPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
@@ -147,7 +149,10 @@ def openModel(self, filename):
dependencies = [];
if dependenceline != str(None):
for index in dependenceline.split(","):
dependencies.append(int(index))
try:
dependencies.append(int(index))
except:
pass #a quick fix fwhile I figure out how to solve problems when parsing this
for param in alg.parameters:
line = lines.readline().strip("\n")
if line==str(None):
@@ -172,10 +177,13 @@ def openModel(self, filename):
self.dependencies.append(dependencies)
iAlg += 1
else:
raise WrongModelException("Error in line: " + line)
raise WrongModelException("Error in algorithm name: " + algLine)
line = lines.readline().strip("\n")
except:
raise WrongModelException("Error in line: " + line)
except Exception, e:
if isinstance (e, WrongModelException):
raise e
else:
raise WrongModelException("Error in model definition line:" + line.strip() + " : " + traceback.format_exc())

def addParameter(self, param):
self.parameters.append(param)
@@ -292,13 +300,13 @@ def getDependsOnAlgorithms(self, algIndex):
'''This method returns a list with the indexes of algorithms a given one depends on'''
algs = []
algs.extend(self.dependencies[algIndex])
index = -1
index = -1
for aap in self.algParameters[algIndex].values():
index += 1
if aap is not None:
if aap.alg != AlgorithmAndParameter.PARENT_MODEL_ALGORITHM and aap.alg not in algs:
algs.append(index)
dep = self.getDependsOnAlgorithms(index)
algs.append(aap.alg)
dep = self.getDependsOnAlgorithms(aap.alg)
for alg in dep:
if alg not in algs:
algs.append(alg)
@@ -496,7 +504,7 @@ def processAlgorithm(self, progress):
canExecute = True
required = self.getDependsOnAlgorithms(iAlg)
for requiredAlg in required:
if requiredAlg not in executed:
if requiredAlg != iAlg and requiredAlg not in executed:
canExecute = False
break
if canExecute:
@@ -523,7 +531,8 @@ def processAlgorithm(self, progress):
progress.setDebugInfo("Failed")
raise GeoAlgorithmExecutionException("Error executing algorithm " + str(iAlg) + "\n" + e.msg)
else:
progress.setDebugInfo("Algorithm %s deactivated (or already executed)" % alg.name)
pass
#progress.setDebugInfo("Algorithm %s deactivated (or already executed)" % alg.name)
iAlg += 1
progress.setDebugInfo("Model processed ok. Executed %i algorithms total" % iAlg)

This file was deleted.

@@ -0,0 +1,45 @@
NAME:Contour lines from points
GROUP:[Example models]
PARAMETER:ParameterVector|VECTORLAYER_SHAPES|Shapes|-1|False
120.0,60.0
PARAMETER:ParameterNumber|NUMBER_INTERVAL|Interval|0.0|None|10.0
633.0,163.0
PARAMETER:ParameterNumber|NUMBER_CELLSIZEFORINTERMEDIATELAYER|Cellsize for intermediate layer|0.0|None|10.0
411.0,84.0
PARAMETER:ParameterTableField|TABLEFIELD_FIELD|Field|VECTORLAYER_SHAPES|-1
104.0,202.0
VALUE:HARDCODEDPARAMVALUE_LINE_TYPE_0===0
VALUE:HARDCODEDPARAMVALUE_ZMAX_2===10000.0
VALUE:HARDCODEDPARAMVALUE_USER_SIZE_0===1.0
VALUE:HARDCODEDPARAMVALUE_ZMIN_2===0.0
VALUE:HARDCODEDPARAMVALUE_THRESHOLD_1===0.1
VALUE:HARDCODEDPARAMVALUE_MULTIPLE_0===0
VALUE:HARDCODEDPARAMVALUE_GRID_TYPE_0===3
VALUE:HARDCODEDPARAMVALUE_TARGET_0===0
ALGORITHM:saga:shapestogrid
348.0,211.0
None
-1|VECTORLAYER_SHAPES
-1|TABLEFIELD_FIELD
-1|HARDCODEDPARAMVALUE_MULTIPLE_0
-1|HARDCODEDPARAMVALUE_LINE_TYPE_0
-1|HARDCODEDPARAMVALUE_GRID_TYPE_0
-1|HARDCODEDPARAMVALUE_TARGET_0
None
-1|NUMBER_CELLSIZEFORINTERMEDIATELAYER
None
ALGORITHM:saga:closegaps
450.0,379.0
None
0|USER_GRID
None
-1|HARDCODEDPARAMVALUE_THRESHOLD_1
None
ALGORITHM:saga:contourlinesfromgrid
630.0,279.0
None
1|RESULT
-1|HARDCODEDPARAMVALUE_ZMIN_2
-1|HARDCODEDPARAMVALUE_ZMAX_2
-1|NUMBER_INTERVAL
Contour lines

This file was deleted.

@@ -0,0 +1,26 @@
NAME:A model with a script
GROUP:[Test models]
PARAMETER:ParameterVector|VECTORLAYER_VECTOR|vector|-1|False
238.0,94.0
VALUE:HARDCODEDPARAMVALUE_DY_1===0.0
VALUE:HARDCODEDPARAMVALUE_ANGLE_1===0.0
VALUE:HARDCODEDPARAMVALUE_SCALEX_1===1.0
VALUE:HARDCODEDPARAMVALUE_ANCHORX_1===0.0
VALUE:HARDCODEDPARAMVALUE_ANCHORY_1===0.0
VALUE:HARDCODEDPARAMVALUE_SCALEY_1===1.0
ALGORITHM:script:ascriptthatreturnsanumber
546.0,150.0
None
None
ALGORITHM:saga:transformshapes
310.0,304.0
None
-1|VECTORLAYER_VECTOR
0|number
-1|HARDCODEDPARAMVALUE_DY_1
-1|HARDCODEDPARAMVALUE_ANGLE_1
-1|HARDCODEDPARAMVALUE_SCALEX_1
-1|HARDCODEDPARAMVALUE_SCALEY_1
-1|HARDCODEDPARAMVALUE_ANCHORX_1
-1|HARDCODEDPARAMVALUE_ANCHORY_1
displaced
@@ -1,9 +1,9 @@
NAME:Watershed from DEM
NAME:Watershed from DEM and threshold
GROUP:[Example models]
PARAMETER:ParameterRaster|RASTERLAYER_DEM|DEM|False
120.0,60.0
PARAMETER:ParameterNumber|NUMBER_STREAMDEFINITIONTHRESHOLD|Stream definition threshold|0.0|None|1000000.0
222.0,473.0
233.0,49.0
PARAMETER:ParameterNumber|NUMBER_THRESHOLDFORCHANNELDEFINITION|Threshold for channel definition|0.0|None|1000000.0
330.0,411.0
VALUE:HARDCODEDPARAMVALUE_Method_1===0
VALUE:HARDCODEDPARAMVALUE_MINSLOPE_0===0.01
VALUE:HARDCODEDPARAMVALUE_SPLIT_4===1
@@ -24,7 +24,7 @@ None
-1|HARDCODEDPARAMVALUE_MINSLOPE_0
None
ALGORITHM:saga:catchmentareaparallel
119.0,299.0
119.0,285.0
None
0|RESULT
None
@@ -47,13 +47,13 @@ None
None
None
ALGORITHM:saga:channelnetwork
418.0,300.0
398.0,283.0
None
0|RESULT
-1|RASTERLAYER_DEM
None
1|CAREA
-1|HARDCODEDPARAMVALUE_INIT_METHOD_2
-1|NUMBER_STREAMDEFINITIONTHRESHOLD
-1|NUMBER_THRESHOLDFORCHANNELDEFINITION
None
-1|HARDCODEDPARAMVALUE_DIV_CELLS_2
None
@@ -62,18 +62,18 @@ None
None
None
ALGORITHM:saga:watershedbasins
578.0,160.0
528.0,48.0
None
0|RESULT
-1|RASTERLAYER_DEM
2|CHNLNTWRK
None
-1|HARDCODEDPARAMVALUE_MINSIZE_3
None
ALGORITHM:saga:vectorisinggridclasses
578.0,481.0
649.0,285.0
None
3|BASINS
-1|HARDCODEDPARAMVALUE_CLASS_ALL_4
-1|HARDCODEDPARAMVALUE_CLASS_ID_4
-1|HARDCODEDPARAMVALUE_SPLIT_4
None
Watersheds
@@ -0,0 +1,4 @@
##[Test scripts]=group
##number=output number

number = 10

0 comments on commit ea6573a

Please sign in to comment.
You can’t perform that action at this time.