Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[matter_yamltests] Add try_apply_float_to_integer_fix since Test_TC_C… #24658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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