Skip to content
Permalink
Browse files

[Bugfix] Processing @alg decorator support input help string (#40207)

(cherry picked from commit 0b28107)
  • Loading branch information
rldhont authored and nyalldawson committed Dec 21, 2020
1 parent da85fb6 commit d9d5f20b2a21719053a00af44c4242daf910c54b
Showing with 33 additions and 0 deletions.
  1. +3 −0 python/processing/algfactory.py
  2. +30 −0 tests/src/python/test_processing_alg_decorator.py
@@ -194,6 +194,7 @@ def _create_param(self, type, output=False, **kwargs):
kwargs['description'] = kwargs.pop("label", "")
kwargs['defaultValue'] = kwargs.pop("default", None)
advanced = kwargs.pop("advanced", False)
help_str = kwargs.pop("help", "")
try:
if output:
try:
@@ -208,6 +209,8 @@ def _create_param(self, type, output=False, **kwargs):
parm = make_func(**kwargs)
if advanced:
parm.setFlags(parm.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
if not output:
parm.setHelp(help_str)
return parm
except KeyError as ex:
raise NotImplementedError("{} not supported".format(str(type)))
@@ -48,6 +48,20 @@ def testalg(instance, parameters, context, feedback, inputs):
"""


def define_new_input_help(newid=1):
@alg(name=ARGNAME.format(newid), label=alg.tr("Test func"), group="unittest",
group_label=alg.tr("Test label"))
@alg.help(HELPSTRING.format(newid))
@alg.input(type=alg.SOURCE, name="INPUT", label="Input layer", help="The input layer as source")
@alg.input(type=alg.DISTANCE, name="DISTANCE", label="Distance", default=30, help="The distance to split the input layer")
@alg.input(type=alg.SINK, name="SINK", label="Output layer", help="The output layer as sink")
@alg.output(type=str, name="DISTANCE_OUT", label="Distance out")
def testalg(instance, parameters, context, feedback, inputs):
"""
Given a distance will split a line layer into segments of the distance
"""


def define_new_doc_string(newid=1):
@alg(name=ARGNAME.format(newid), label=alg.tr("Test func"), group="unittest",
group_label=alg.tr("Test label"))
@@ -151,6 +165,22 @@ def test_has_help_from_docstring(self):
current = alg.instances.pop()
self.assertEqual("Test doc string text", current.shortHelpString())

def test_has_input_help(self):
define_new_input_help()
current = alg.instances.pop()
current.initAlgorithm()
defs = current.parameterDefinitions()
self.assertEqual(3, len(defs))
inputs = [
("INPUT", "The input layer as source"),
("DISTANCE", "The distance to split the input layer"),
("SINK", "The output layer as sink"),
]
for count, data in enumerate(inputs):
parmdef = defs[count]
self.assertEqual(data[0], parmdef.name())
self.assertEqual(data[1], parmdef.help())


class TestAlg(unittest.TestCase):

0 comments on commit d9d5f20

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