Skip to content
Permalink
Browse files
Add unit tests for processing expression parameter
  • Loading branch information
nyalldawson committed Nov 11, 2016
1 parent 5625d6e commit 156fce989d29e149ce7d9d8db2975e9e032f581f
Showing with 26 additions and 2 deletions.
  1. +26 −2 python/plugins/processing/tests/ParametersTest.py
@@ -40,7 +40,8 @@
ParameterString,
ParameterVector,
ParameterTableField,
ParameterSelection)
ParameterSelection,
ParameterExpression)
from processing.tools import dataobjects
from processing.tests.TestData import points2

@@ -462,7 +463,30 @@ def testOptional(self):
self.assertTrue(optionalParameter.setValue(None))
self.assertEqual(optionalParameter.value, None)

requiredParameter = ParameterCrs('myName', 'myDesc', default='test', optional=False)
requiredParameter = ParameterString('myName', 'myDesc', default='test', optional=False)
self.assertEqual(requiredParameter.value, 'test')
requiredParameter.setValue('check')
self.assertEqual(requiredParameter.value, 'check')
self.assertFalse(requiredParameter.setValue(None))
self.assertEqual(requiredParameter.value, 'check')


class ParameterExpressionTest(unittest.TestCase):

def testSetValue(self):
parameter = ParameterExpression('myName', 'myDescription')
self.assertTrue(parameter.setValue('\'a\' || "field"'))
self.assertEqual(parameter.value, '\'a\' || "field"')

def testOptional(self):
optionalParameter = ParameterExpression('myName', 'myDesc', default='test', optional=True)
self.assertEqual(optionalParameter.value, 'test')
optionalParameter.setValue('check')
self.assertEqual(optionalParameter.value, 'check')
self.assertTrue(optionalParameter.setValue(None))
self.assertEqual(optionalParameter.value, None)

requiredParameter = ParameterExpression('myName', 'myDesc', default='test', optional=False)
self.assertEqual(requiredParameter.value, 'test')
requiredParameter.setValue('check')
self.assertEqual(requiredParameter.value, 'check')

0 comments on commit 156fce9

Please sign in to comment.