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