Skip to content

Commit

Permalink
[matter_yamltests] Update values from config variables at beginning t…
Browse files Browse the repository at this point in the history
…o make it possible to decode hex: values to bytes (#24570)
  • Loading branch information
vivien-apple authored and pull[bot] committed Feb 13, 2024
1 parent 384e8ce commit 6007061
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def convert_yaml_octet_string_to_bytes(s: str) -> bytes:
This handles any c-style hex escapes (e.g. \x5a) and hex: prefix
'''
# Step 0: Check if this is already of type bytes
if isinstance(s, bytes):
return s

# Step 1: handle explicit "hex:" prefix
if s.startswith('hex:'):
return binascii.unhexlify(s[4:])
Expand Down
20 changes: 15 additions & 5 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
response_mapping = self._as_mapping(
definitions, self.cluster, command.output_param)

self._update_with_definition(
self.arguments_with_placeholders, argument_mapping)
self._update_with_definition(
self.response_with_placeholders, response_mapping)
self.argument_mapping = argument_mapping
self.response_mapping = response_mapping
self.update_arguments(self.arguments_with_placeholders)
self.update_response(self.response_with_placeholders)

# This performs a very basic sanity parse time check of constrains. This parsing happens
# This performs a very basic sanity parse time check of constraints. This parsing happens
# again inside post processing response since at that time we will have required variables
# to substitute in. This parsing check here has value since some test can take a really
# long time to run so knowing earlier on that the test step would have failed at parsing
Expand Down Expand Up @@ -299,6 +299,14 @@ def _as_mapping(self, definitions, cluster_name, target_name):

return target_name

def update_arguments(self, arguments_with_placeholders):
self._update_with_definition(
arguments_with_placeholders, self.argument_mapping)

def update_response(self, response_with_placeholders):
self._update_with_definition(
response_with_placeholders, self.response_mapping)

def _update_with_definition(self, container: dict, mapping_type):
if not container or not mapping_type:
return
Expand Down Expand Up @@ -387,6 +395,8 @@ def __init__(self, test: _TestStepWithPlaceholders, runtime_config_variable_stor
self.response = copy.deepcopy(test.response_with_placeholders)
self._update_placeholder_values(self.arguments)
self._update_placeholder_values(self.response)
test.update_arguments(self.arguments)
test.update_response(self.response)

@property
def is_enabled(self):
Expand Down

0 comments on commit 6007061

Please sign in to comment.