Skip to content
Permalink
Browse files

[processing][grass] Fix broken checkParameterValues tests

  • Loading branch information
nyalldawson committed May 28, 2018
1 parent 870d207 commit a26ae3c1d962a96c549f918cd954ea8b49d3da56
@@ -986,6 +986,5 @@ def checkParameterValues(self, parameters, context):
if self.module:
if hasattr(self.module, 'checkParameterValuesBeforeExecuting'):
func = getattr(self.module, 'checkParameterValuesBeforeExecuting')
#return func(self, parameters, context), None
return None, func(self, parameters, context)
return func(self, parameters, context)
return super(Grass7Algorithm, self).checkParameterValues(parameters, context)
@@ -168,10 +168,10 @@ def verifyRasterNum(alg, parameters, context, rasters, mini, maxi=None):
"""Verify that we have at least n rasters in multipleInput"""
num = len(alg.parameterAsLayerList(parameters, rasters, context))
if num < mini:
return 'You need to set at least {} input rasters for this algorithm!'.format(mini)
return False, 'You need to set at least {} input rasters for this algorithm!'.format(mini)
if maxi and num > maxi:
return 'You need to set a maximum of {} input rasters for this algorithm!'.format(maxi)
return None
return False, 'You need to set a maximum of {} input rasters for this algorithm!'.format(maxi)
return True, None


# def file2Output(alg, output):
@@ -36,4 +36,4 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
elif (alg.parameterAsBool(parameters, '-l', context)
or alg.parameterAsBool(parameters, '-a', context)):
return verifyRasterNum(alg, parameters, context, 'input', 6)
return None
return True, None
@@ -29,8 +29,8 @@
def checkParameterValuesBeforeExecuting(alg, parameters, context):
if (alg.parameterAsBool(parameters, '-h', context)
and alg.parameterAsLayer(parameters, 'precipitation', context)):
return alg.tr('You can\'t use original Hargreaves flag and precipitation parameter together!')
return False, alg.tr('You can\'t use original Hargreaves flag and precipitation parameter together!')
if (not alg.parameterAsBool(parameters, '-h', context)
and not alg.parameterAsLayer(parameters, 'precipitation', context)):
return alg.tr('If you don\'t use original Hargreaves flag, you must set the precipitation raster parameter!')
return None
return False, alg.tr('If you don\'t use original Hargreaves flag, you must set the precipitation raster parameter!')
return True, None
@@ -36,11 +36,11 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
raster = alg.parameterAsString(parameters, 'raster', context)

if rules and txtrules:
return alg.tr("You need to set either a rules file or write directly the rules!")
return False, alg.tr("You need to set either a rules file or write directly the rules!")
elif (rules and raster) or (txtrules and raster):
return alg.tr("You need to set either rules or a raster from which to copy categories!")
return False, alg.tr("You need to set either rules or a raster from which to copy categories!")

return None
return True, None


def processInputs(alg, parameters, context, feedback):
@@ -35,9 +35,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
txtRules = alg.parameterAsString(parameters, 'rules_txt', context)
rules = alg.parameterAsString(parameters, 'rules', context)
if txtRules and rules:
return alg.tr("You need to set either inline rules or a rules file!")
return False, alg.tr("You need to set either inline rules or a rules file!")

return None
return True, None


def processInputs(alg, parameters, context, feedback):
@@ -31,15 +31,15 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
# start_coordinates and start_points are mutually exclusives
if (alg.parameterAsString(parameters, 'start_coordinates', context)
and alg.parameterAsVectorLayer(parameters, 'start_points', context)):
return alg.tr("You need to set either start coordinates OR a start points vector layer!")
return False, alg.tr("You need to set either start coordinates OR a start points vector layer!")

# You need to set at least one parameter
if (not alg.parameterAsString(parameters, 'start_coordinates', context)
and not alg.parameterAsVectorLayer(parameters, 'start_points', context)):
return alg.tr("You need to set either start coordinates OR a start points vector layer!")
return False, alg.tr("You need to set either start coordinates OR a start points vector layer!")

paramscore = [f for f in ['-c', '-a', '-n']
if alg.parameterAsBool(parameters, f, context)]
if len(paramscore) > 1:
return alg.tr("-c, -a, -n parameters are mutually exclusive!")
return None
return False, alg.tr("-c, -a, -n parameters are mutually exclusive!")
return True, None
@@ -34,10 +34,10 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
step = alg.parameterAsDouble(parameters, 'step', context)

if start >= end:
return alg.tr("The start position must be inferior to the end position!")
return False, alg.tr("The start position must be inferior to the end position!")
if step == 0.0:
return alg.tr("The step must be greater than zero!")
return None
return False, alg.tr("The step must be greater than zero!")
return True, None


def processOutputs(alg, parameters, context, feedback):
@@ -60,7 +60,7 @@ def checkMovingWindow(alg, parameters, context, outputTxt=False):
configTxt = alg.parameterAsString(parameters, 'config_txt', context)
config = alg.parameterAsString(parameters, 'config', context)
if configTxt and config:
return alg.tr("You need to set either inline configuration or a configuration file!")
return False, alg.tr("You need to set either inline configuration or a configuration file!")

# Verify that configuration is in moving window
movingWindow = False
@@ -76,12 +76,12 @@ def checkMovingWindow(alg, parameters, context, outputTxt=False):
movingWindow = True

if not movingWindow and not outputTxt:
return alg.tr('Your configuration needs to be a "moving window" configuration!')
return False, alg.tr('Your configuration needs to be a "moving window" configuration!')

if movingWindow and outputTxt:
return alg.tr('Your configuration needs to be a non "moving window" configuration!')
return False, alg.tr('Your configuration needs to be a non "moving window" configuration!')

return None
return True, None


def configFile(alg, parameters, context, feedback, outputTxt=False):
@@ -32,9 +32,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if (alg.parameterAsString(parameters, 'expression', context)
and alg.parameterAsString(parameters, 'file', context)):
return alg.tr("You need to set either inline expression or a rules file!")
return False, alg.tr("You need to set either inline expression or a rules file!")

return None
return True, None


def processInputs(alg, parameters, context, feedback):
@@ -30,9 +30,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if (alg.parameterAsString(parameters, 'setnull', context)
or alg.parameterAsString(parameters, 'null', context)):
return None
return True, None

return alg.tr("You need to set at least 'setnull' or 'null' parameters for this algorithm!")
return False, alg.tr("You need to set at least 'setnull' or 'null' parameters for this algorithm!")


def processInputs(alg, parameters, context, feedback):
@@ -33,9 +33,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if (alg.parameterAsString(parameters, 'rules', context)
and alg.parameterAsString(parameters, 'txtrules', context)):
return alg.tr("You need to set either a rules file or write directly the rules!")
return False, alg.tr("You need to set either a rules file or write directly the rules!")

return None
return True, None


def processCommand(alg, parameters, context, feedback):
@@ -33,7 +33,7 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
y_radius = alg.parameterAsString(parameters, 'y_radius', context)

if (not radius and not x_radius and not y_radius) or (radius and (x_radius or y_radius)):
return alg.tr("You need to set either radius or x_radius and y_radius!")
return False, alg.tr("You need to set either radius or x_radius and y_radius!")
elif (x_radius and not y_radius) or (y_radius and not x_radius):
return alg.tr("You need to set x_radius and y_radius!")
return None
return False, alg.tr("You need to set x_radius and y_radius!")
return True, None
@@ -37,12 +37,12 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
outfile = alg.parameterAsString(parameters, 'outfile', context)

if datapos and infile:
return alg.tr("You need to set either inline data positions or an input data positions file!")
return False, alg.tr("You need to set either inline data positions or an input data positions file!")
if output and outfile:
return alg.tr("You need to set either sampling data positions or an output sampling data positions file!")
return False, alg.tr("You need to set either sampling data positions or an output sampling data positions file!")
if not (datapos or infile or output or outfile):
return alg.tr("You need to set input and output data positions parameters!")
return None
return False, alg.tr("You need to set input and output data positions parameters!")
return True, None


def processCommand(alg, parameters, context, feedback):
@@ -34,9 +34,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
uploads = alg.parameterAsEnums(parameters, 'upload', context)
columns = alg.parameterAsFields(parameters, 'column', context)
if len(columns) != len(uploads):
return alg.tr(u"The number of columns and the number of upload parameters should be equal!")
return False, alg.tr(u"The number of columns and the number of upload parameters should be equal!")

return None
return True, None


def processCommand(alg, parameters, context, feedback):
@@ -34,9 +34,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if (alg.parameterAsString(parameters, 'input_txt', context)
and alg.parameterAsString(parameters, 'input', context)):
return alg.tr("You need to set either an input ASCII file or inline data!")
return False, alg.tr("You need to set either an input ASCII file or inline data!")

return None
return True, None


def processCommand(alg, parameters, context, feedback):
@@ -31,6 +31,6 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
height = alg.parameterAsDouble(parameters, 'height', context)
height_column = alg.parameterAsString(parameters, 'height_column', context)
if (height and height_column) or (not height and not height_column):
return alg.tr("You need to set either a fixed height value or the height column!")
return False, alg.tr("You need to set either a fixed height value or the height column!")

return None
return True, None
@@ -43,9 +43,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
)

if (values[0] or values[2]) and (values[1] or values[3]):
return None
return True, None

return alg.tr("You need to set at least setX_where or setX_cats parameters for each set!")
return False, alg.tr("You need to set at least setX_where or setX_cats parameters for each set!")


def processCommand(alg, parameters, context, feedback):
@@ -44,9 +44,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
)

if (values[0] or values[2]) and (values[1] or values[3]):
return None
return True, None

return alg.tr("You need to set at least source/sink_where or source/sink_cats parameters for each set!")
return False, alg.tr("You need to set at least source/sink_where or source/sink_cats parameters for each set!")


def processCommand(alg, parameters, context, feedback):
@@ -34,9 +34,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if (alg.parameterAsString(parameters, 'inline_points', context)
and alg.parameterAsString(parameters, 'points', context)):
return alg.tr("You need to set either an input control point file or inline control points!")
return False, alg.tr("You need to set either an input control point file or inline control points!")

return None
return True, None


def processCommand(alg, parameters, context, feedback):
@@ -31,9 +31,9 @@ def checkParameterValuesBeforeExecuting(alg, parameters, context):
height = alg.parameterAsDouble(parameters, 'height', context)
column = alg.parameterAsString(parameters, 'column', context)
if (height and column) or (not height and not column):
return alg.tr("You need to set either a fixed height value or the height column!")
return False, alg.tr("You need to set either a fixed height value or the height column!")

return None
return True, None


def processInputs(alg, parameters, context, feedback):

0 comments on commit a26ae3c

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