Skip to content

Commit

Permalink
[processing] add tests for ParameterPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 29, 2016
1 parent 58d40d1 commit 841de7e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion python/plugins/processing/tests/ParametersTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
ParameterFile,
ParameterFixedTable,
ParameterMultipleInput,
ParameterNumber)
ParameterNumber,
ParameterPoint)

from qgis.core import (QgsRasterLayer,
QgsVectorLayer)
Expand Down Expand Up @@ -154,6 +155,36 @@ def testOptional(self):
self.assertEqual(requiredParameter.value, '1,2,3,4')


class ParameterPointTest(unittest.TestCase):

def testSetValue(self):
parameter = ParameterPoint('myName', 'myDesc')
self.assertTrue(parameter.setValue('0,2'))
self.assertEqual(parameter.value, '0,2')

def testSetInvalidValue(self):
parameter = ParameterPoint('myName', 'myDesc')
self.assertFalse(parameter.setValue('0'))
self.assertFalse(parameter.setValue('0,a'))

def testOptional(self):
optionalParameter = ParameterPoint('myName', 'myDesc', default='0,1', optional=True)
self.assertEqual(optionalParameter.value, '0,1')
optionalParameter.setValue('1,2')
self.assertEqual(optionalParameter.value, '1,2')
self.assertTrue(optionalParameter.setValue(None))
# Extent is unique in that it will let you set `None`, whereas other
# optional parameters become "default" when assigning None.
self.assertEqual(optionalParameter.value, None)

requiredParameter = ParameterPoint('myName', 'myDesc', default='0,1', optional=False)
self.assertEqual(requiredParameter.value, '0,1')
requiredParameter.setValue('1,2')
self.assertEqual(requiredParameter.value, '1,2')
self.assertFalse(requiredParameter.setValue(None))
self.assertEqual(requiredParameter.value, '1,2')


class ParameterFileTest(unittest.TestCase):

def testSetValue(self):
Expand Down

0 comments on commit 841de7e

Please sign in to comment.