Skip to content
Permalink
Browse files

[Processing] Fix ParameterNumber float detection (with unit tests)

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Feb 9, 2016
1 parent d11c689 commit 5d19a3b21b614fb05c45f7c2830d954972766b14
Showing with 12 additions and 2 deletions.
  1. +2 −2 python/plugins/processing/core/parameters.py
  2. +10 −0 python/plugins/processing/tests/ParametersTest.py
@@ -446,9 +446,9 @@ def __init__(self, name='', description='', minValue=None, maxValue=None,

if default is not None:
try:
self.default = int(float(default))
self.default = int(unicode(default))
self.isInteger = True
except:
except ValueError:
self.default = float(default)
self.isInteger = False
else:
@@ -308,6 +308,16 @@ def testSetValueOnlyValidNumbers(self):
self.assertFalse(parameter.setValue('not a number'))
self.assertEqual(parameter.value, None)

def testIsInteger(self):
floatParameter = ParameterNumber('myname', 'myDescription', default=1.0)
self.assertFalse(floatParameter.isInteger)
intParameter = ParameterNumber('myname', 'myDescription', default=10)
self.assertTrue(intParameter.isInteger)
strFloatParameter = ParameterNumber('myname', 'myDescription', default="1.0")
self.assertFalse(strFloatParameter.isInteger)
strIntParameter = ParameterNumber('myname', 'myDescription', default="10")
self.assertTrue(strIntParameter.isInteger)

def testMaxValue(self):
parameter = ParameterNumber('myName', 'myDescription', maxValue=10)
self.assertFalse(parameter.setValue(11))

0 comments on commit 5d19a3b

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