Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Processing] Fix ParameterNumber float detection (with unit tests)
  • Loading branch information
Médéric RIBREUX committed Feb 9, 2016
1 parent d11c689 commit 5d19a3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/plugins/processing/core/parameters.py
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions python/plugins/processing/tests/ParametersTest.py
Expand Up @@ -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))
Expand Down

0 comments on commit 5d19a3b

Please sign in to comment.