Skip to content
Permalink
Browse files

[processing] Quote and escape script exported ParameterString

  • Loading branch information
m-kuhn committed Dec 22, 2016
1 parent 55e3ea0 commit 3fba3ac7759907ddac447ad339207ea1ad6a4527
Showing with 20 additions and 1 deletion.
  1. +3 −1 python/plugins/processing/core/parameters.py
  2. +17 −0 python/plugins/processing/tests/ParametersTest.py
@@ -1191,7 +1191,7 @@ def getAsScriptCode(self):
if self.optional:
param_type += 'optional '
param_type += 'string '
return '##' + self.name + '=' + param_type + str(self.default)
return '##' + self.name + '=' + param_type + repr(self.default)

@classmethod
def fromScriptCode(self, line):
@@ -1201,6 +1201,8 @@ def fromScriptCode(self, line):
default = definition.strip()[len('string') + 1:] or None
if default == 'None':
default = None
elif default.startswith('"') or default.startswith('\''):
default = eval(default)
if default:
return ParameterString(name, descName, default, optional=isOptional)
else:
@@ -593,12 +593,29 @@ def testScriptCode(self):
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertIsInstance(result, ParameterString)
self.assertEqual(result.default, parameter.default)

parameter.default = None
parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertIsInstance(result, ParameterString)
self.assertTrue(result.optional)
self.assertEqual(result.default, parameter.default)

parameter.default = 'None'
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertIsInstance(result, ParameterString)
self.assertTrue(result.optional)
self.assertEqual(result.default, parameter.default)

parameter.default = 'It\'s Mario'
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertIsInstance(result, ParameterString)
self.assertTrue(result.optional)
self.assertEqual(result.default, parameter.default)


class ParameterExpressionTest(unittest.TestCase):

0 comments on commit 3fba3ac

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