allow type promotion to float
This commit is contained in:
parent
33d852b2e4
commit
5c496a3078
@ -269,6 +269,11 @@ class TestTypes(unittest.TestCase):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def test_validate_float(self):
|
||||
self.assertEqual(types.validate_value(float, 1), 1.0)
|
||||
self.assertEqual(types.validate_value(float, '1'), 1.0)
|
||||
self.assertEqual(types.validate_value(float, 1.1), 1.1)
|
||||
|
||||
def test_register_invalid_array(self):
|
||||
self.assertRaises(ValueError, types.register_type, [])
|
||||
self.assertRaises(ValueError, types.register_type, [int, str])
|
||||
|
@ -218,6 +218,8 @@ def validate_value(datatype, value):
|
||||
value = value.decode()
|
||||
elif datatype is bytes and isinstance(value, text):
|
||||
value = value.encode()
|
||||
elif datatype is float and not isinstance(value, float):
|
||||
value = float(value)
|
||||
elif not isinstance(value, datatype):
|
||||
raise ValueError(
|
||||
"Wrong type. Expected '%s', got '%s'" % (
|
||||
|
Loading…
x
Reference in New Issue
Block a user