Skip to content

Commit

Permalink
Added key verification
Browse files Browse the repository at this point in the history
  • Loading branch information
v-i-n-y-a committed Aug 26, 2024
1 parent f6c5575 commit c372dd0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
RIOS.CORE Change History
************************

0.10.0 (2024-08-27)
===================

* Range validation fixes.


0.9.0 (2020-06-12)
==================
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
46 changes: 24 additions & 22 deletions src/rios/core/validation/assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
17 changes: 17 additions & 0 deletions tests/examples/instruments/good/type_range_float_max.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}

17 changes: 17 additions & 0 deletions tests/examples/instruments/good/type_range_float_min.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}

0 comments on commit c372dd0

Please sign in to comment.