Skip to content

Commit

Permalink
Add unit tests for processing expression parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 11, 2016
1 parent 5625d6e commit 156fce9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions python/plugins/processing/tests/ParametersTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
ParameterString,
ParameterVector,
ParameterTableField,
ParameterSelection)
ParameterSelection,
ParameterExpression)
from processing.tools import dataobjects
from processing.tests.TestData import points2

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 156fce9

Please sign in to comment.