Skip to content

Commit 4026044

Browse files
vivien-applepull[bot]
authored andcommitted
[matter_yamltests] Add try_apply_float_to_integer_fix since Test_TC_CC_6_2 makes math operation to configure a value that ends up as a float while a int is expected (#24658)
1 parent 0120969 commit 4026044

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

scripts/py_matter_yamltests/matter_yamltests/fixes.py

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ def try_apply_yaml_cpp_longlong_limitation_fix(value):
3535
return value
3636

3737

38+
def try_apply_float_to_integer_fix(value):
39+
'''Fix math operations where values ends up beeing a float for integer types.
40+
41+
For example one of the color control test configure the ColoremperatureMireds value to be:
42+
(ColorTempPhysicalMinMireds + ColorTempPhysicalMaxMireds)/2
43+
In this specific example it ends up as '32639.5', which is invalid.
44+
'''
45+
if isinstance(value, float):
46+
return int(value)
47+
return value
48+
49+
3850
def try_apply_yaml_unrepresentable_integer_for_javascript_fixes(value):
3951
'''Fix up large integers that are represented within a string.
4052

scripts/py_matter_yamltests/matter_yamltests/parser.py

+3
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,14 @@ def _update_value_with_definition(self, value, mapping_type):
371371
# the wrong thing below.
372372
if value is not None and value not in self._parsing_config_variable_storage:
373373
if mapping_type == 'int64u' or mapping_type == 'int64s' or mapping_type == 'bitmap64' or mapping_type == 'epoch_us':
374+
value = fixes.try_apply_float_to_integer_fix(value)
374375
value = fixes.try_apply_yaml_cpp_longlong_limitation_fix(value)
375376
value = fixes.try_apply_yaml_unrepresentable_integer_for_javascript_fixes(
376377
value)
377378
elif mapping_type == 'single' or mapping_type == 'double':
378379
value = fixes.try_apply_yaml_float_written_as_strings(value)
380+
elif isinstance(value, float) and mapping_type != 'single' and mapping_type != 'double':
381+
value = fixes.try_apply_float_to_integer_fix(value)
379382
elif mapping_type == 'octet_string' or mapping_type == 'long_octet_string':
380383
value = fixes.convert_yaml_octet_string_to_bytes(value)
381384
elif mapping_type == 'boolean':

0 commit comments

Comments
 (0)