diff --git a/CHANGES.rst b/CHANGES.rst index de0ebda..164637f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,11 @@ RIOS.CORE Change History ************************ +0.10.0 (2024-08-27) +=================== + +* Range validation fixes. + 0.9.0 (2020-06-12) ================== diff --git a/setup.py b/setup.py index 8923bde..3171be6 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='rios.core', - version='0.9.0', + version='0.10.0', description='Parsing and Validation Library for RIOS Files', long_description=open('README.rst', 'r').read(), keywords='rios prismh research instrument assessment standard validation', diff --git a/src/rios/core/validation/assessment.py b/src/rios/core/validation/assessment.py index 1f6ca97..384b516 100644 --- a/src/rios/core/validation/assessment.py +++ b/src/rios/core/validation/assessment.py @@ -298,31 +298,33 @@ def _check_value_constraints(self, node, value, field, type_def): if type_def.get('range'): casted_value = self._cast_range(value, type_def['base']) - casted_min = self._cast_range( - type_def['range']['min'], - type_def['base'], - ) - if type_def['range'].get('min') is not None \ - and casted_value < casted_min: - raise ValidationError( - node, - 'Value for "%s" is less than acceptible minimum' % ( - field['id'], - ), + min_range_value = type_def['range'].get('min') + if min_range_value is not None: + casted_min = self._cast_range( + type_def['range']['min'], + type_def['base'], ) + if casted_value < casted_min: + raise ValidationError( + node, + 'Value for "%s" is less than acceptible minimum' % ( + field['id'], + ), + ) - casted_max = self._cast_range( - type_def['range']['max'], - type_def['base'], - ) - if type_def['range'].get('max') is not None \ - and casted_value > casted_max: - raise ValidationError( - node, - 'Value for "%s" is greater than acceptible maximum' % ( - field['id'], - ), + max_range_value = type_def['range'].get('max') + if max_range_value is not None: + casted_max = self._cast_range( + type_def['range']['max'], + type_def['base'], ) + if casted_value > casted_max: + raise ValidationError( + node, + 'Value for "%s" is greater than acceptible maximum' % ( + field['id'], + ), + ) def _cast_range(self, value, type_base): if type_base in ('integer', 'float'): diff --git a/tests/examples/instruments/good/type_range_float_max.json b/tests/examples/instruments/good/type_range_float_max.json new file mode 100644 index 0000000..a7d0c74 --- /dev/null +++ b/tests/examples/instruments/good/type_range_float_max.json @@ -0,0 +1,17 @@ +{ + "id": "urn:example:bad:range:float:reversed", + "version": "1.0", + "title": "An Instrument Title", + "record": [ + { + "id": "field1", + "type": { + "base": "float", + "range": { + "max": 10.5 + } + } + } + ] +} + diff --git a/tests/examples/instruments/good/type_range_float_min.json b/tests/examples/instruments/good/type_range_float_min.json new file mode 100644 index 0000000..6aef29b --- /dev/null +++ b/tests/examples/instruments/good/type_range_float_min.json @@ -0,0 +1,17 @@ +{ + "id": "urn:example:bad:range:float:reversed", + "version": "1.0", + "title": "An Instrument Title", + "record": [ + { + "id": "field1", + "type": { + "base": "float", + "range": { + "min": 2.1 + } + } + } + ] +} +