Skip to content
Permalink
Browse files

Merge pull request #2774 from medspx/processing_fix_parameternumber

[processing] fix ParameterNumber float detection
  • Loading branch information
alexbruy committed Feb 11, 2016
2 parents 169d35f + 5d19a3b commit 0d652b2fe0df595501bfa9536346f59fa91aa3bd
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 0d652b2

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