Fix TypeError
Fix TypeError thrown while calling InvalidSchemaError Change-Id: I4527afe05258a200ce932ed0bec86613abd25920 Closes-Bug: 1563542
This commit is contained in:
parent
4ff5fd7534
commit
ea84906ff0
@ -388,17 +388,16 @@ class InRange(Constraint):
|
||||
InvalidSchemaError(message=_('The property "in_range" '
|
||||
'expects a list.')))
|
||||
|
||||
msg = _('The property "in_range" expects comparable values.')
|
||||
for value in self.constraint_value:
|
||||
if not isinstance(value, self.valid_types):
|
||||
ExceptionCollector.appendException(
|
||||
InvalidSchemaError(_('The property "in_range" expects '
|
||||
'comparable values.')))
|
||||
InvalidSchemaError(message=msg))
|
||||
# The only string we allow for range is the special value
|
||||
# 'UNBOUNDED'
|
||||
if(isinstance(value, str) and value != self.UNBOUNDED):
|
||||
ExceptionCollector.appendException(
|
||||
InvalidSchemaError(_('The property "in_range" expects '
|
||||
'comparable values.')))
|
||||
InvalidSchemaError(message=msg))
|
||||
|
||||
self.min = self.constraint_value[0]
|
||||
self.max = self.constraint_value[1]
|
||||
|
@ -68,8 +68,14 @@ class DataTypeTest(TestCase):
|
||||
properties:
|
||||
temperature:
|
||||
type: range
|
||||
required: false
|
||||
constraints:
|
||||
- in_range: [-256, UNBOUNDED]
|
||||
humidity:
|
||||
type: range
|
||||
required: false
|
||||
constraints:
|
||||
- in_range: [-256, INFINITY]
|
||||
'''
|
||||
custom_type_def = yamlparser.simple_parse(custom_type_schema)
|
||||
|
||||
@ -380,6 +386,18 @@ class DataTypeTest(TestCase):
|
||||
),
|
||||
err.__str__())
|
||||
|
||||
value_snippet = '''
|
||||
humidity: [-100, 100]
|
||||
'''
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.TestLab',
|
||||
value, DataTypeTest.custom_type_def)
|
||||
err = self.assertRaises(exception.InvalidSchemaError,
|
||||
lambda: data.validate())
|
||||
self.assertEqual(_('The property "in_range" expects comparable values.'
|
||||
),
|
||||
err.__str__())
|
||||
|
||||
def test_range_unbounded(self):
|
||||
value_snippet = '''
|
||||
temperature: [-100, 999999]
|
||||
|
Loading…
x
Reference in New Issue
Block a user