From ea84906ff025c798bdda52f7bf06267bc9b9e6f0 Mon Sep 17 00:00:00 2001 From: Sahdev Zala <spzala@us.ibm.com> Date: Tue, 29 Mar 2016 13:42:33 -0700 Subject: [PATCH] Fix TypeError Fix TypeError thrown while calling InvalidSchemaError Change-Id: I4527afe05258a200ce932ed0bec86613abd25920 Closes-Bug: 1563542 --- toscaparser/elements/constraints.py | 7 +++---- toscaparser/tests/test_datatypes.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/toscaparser/elements/constraints.py b/toscaparser/elements/constraints.py index 896c0e06..9883da3d 100644 --- a/toscaparser/elements/constraints.py +++ b/toscaparser/elements/constraints.py @@ -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] diff --git a/toscaparser/tests/test_datatypes.py b/toscaparser/tests/test_datatypes.py index ba48ed62..0e613b2a 100644 --- a/toscaparser/tests/test_datatypes.py +++ b/toscaparser/tests/test_datatypes.py @@ -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]