Skip to content

Commit

Permalink
[matter_yamltests] Add try_apply_float_to_integer_fix since Test_TC_C…
Browse files Browse the repository at this point in the history
…C_6_2 makes math operation to configure a value that ends up as a float while a int is expected (#24658)
  • Loading branch information
vivien-apple authored Jan 26, 2023
1 parent 89d538c commit 3d104ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def try_apply_yaml_cpp_longlong_limitation_fix(value):
return value


def try_apply_float_to_integer_fix(value):
'''Fix math operations where values ends up beeing a float for integer types.
For example one of the color control test configure the ColoremperatureMireds value to be:
(ColorTempPhysicalMinMireds + ColorTempPhysicalMaxMireds)/2
In this specific example it ends up as '32639.5', which is invalid.
'''
if isinstance(value, float):
return int(value)
return value


def try_apply_yaml_unrepresentable_integer_for_javascript_fixes(value):
'''Fix up large integers that are represented within a string.
Expand Down
3 changes: 3 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,14 @@ def _update_value_with_definition(self, value, mapping_type):
# the wrong thing below.
if value is not None and value not in self._parsing_config_variable_storage:
if mapping_type == 'int64u' or mapping_type == 'int64s' or mapping_type == 'bitmap64' or mapping_type == 'epoch_us':
value = fixes.try_apply_float_to_integer_fix(value)
value = fixes.try_apply_yaml_cpp_longlong_limitation_fix(value)
value = fixes.try_apply_yaml_unrepresentable_integer_for_javascript_fixes(
value)
elif mapping_type == 'single' or mapping_type == 'double':
value = fixes.try_apply_yaml_float_written_as_strings(value)
elif isinstance(value, float) and mapping_type != 'single' and mapping_type != 'double':
value = fixes.try_apply_float_to_integer_fix(value)
elif mapping_type == 'octet_string' or mapping_type == 'long_octet_string':
value = fixes.convert_yaml_octet_string_to_bytes(value)
elif mapping_type == 'boolean':
Expand Down

0 comments on commit 3d104ef

Please sign in to comment.