Skip to content

Commit

Permalink
[Bugfix] Processing @alg decorator support input help string (#40207)
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Dec 15, 2020
1 parent b465fd1 commit 0b28107
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/processing/algfactory.py
Expand Up @@ -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:
Expand All @@ -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)))
Expand Down
30 changes: 30 additions & 0 deletions tests/src/python/test_processing_alg_decorator.py
Expand Up @@ -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"))
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 0b28107

Please sign in to comment.