Skip to content

Commit

Permalink
[qgis_process] Add unit test for running algorithm with very complex
Browse files Browse the repository at this point in the history
parameter names
  • Loading branch information
nyalldawson committed Feb 8, 2022
1 parent e21ece0 commit 2aaab9f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/src/python/test_qgsprocessexecutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@ def testPythonScriptHelpError(self):
self.assertEqual(rc, 1)
self.assertIn('is not a valid Processing script', err)

def testComplexParameterNames(self):
rc, output, err = self.run_process(['run', TEST_DATA_DIR + '/complex_names.py', '--INPUT with many complex chars.123 a=abc', '--another% complex# NaMe=def'])
if os.environ.get('TRAVIS', '') != 'true':
# Travis DOES have errors, due to QStandardPaths: XDG_RUNTIME_DIR not set warnings raised by Qt
self.assertFalse(err)

self.assertIn('OUTPUT: abc:def', output)
self.assertEqual(rc, 0)


if __name__ == '__main__':
# look for qgis bin path
Expand Down
73 changes: 73 additions & 0 deletions tests/testdata/complex_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsProcessing,
QgsFeatureSink,
QgsProcessingException,
QgsProcessingAlgorithm,
QgsProcessingParameterString,
QgsProcessingOutputString)
from qgis import processing


class AlgWithComplexParamNames(QgsProcessingAlgorithm):

# Constants used to refer to parameters and outputs. They will be
# used when calling the algorithm from another algorithm, or when
# calling from the QGIS console.

INPUT = 'INPUT with many complex chars.123 a'
INPUT2 = 'another% complex# NaMe'
OUTPUT = 'OUTPUT'

def createInstance(self):
return AlgWithComplexParamNames()

def name(self):
return 'complex .name$'

def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterString(
self.INPUT,
'Input string 1'
)
)
self.addParameter(
QgsProcessingParameterString(
self.INPUT2,
'Input string 2'
)
)

self.addOutput(
QgsProcessingOutputString(
self.OUTPUT,
'Output string'
)
)

def processAlgorithm(self, parameters, context, feedback):
string1 = self.parameterAsString(
parameters,
self.INPUT,
context
)
string2 = self.parameterAsString(
parameters,
self.INPUT2,
context
)

return {self.OUTPUT: string1.lower() + ':' + string2.lower()}

0 comments on commit 2aaab9f

Please sign in to comment.