Skip to content

Commit

Permalink
Convert former python yaml tests parser to be a runner/adapter (#24103)
Browse files Browse the repository at this point in the history
* Convert former python yaml tests parser to be a runner/adapter

A common intermediary python YAML test parser has been created. This
removes all the YAML python parsing bits from the current chip-repl
version. It then turns that former parse into a runner that converts
TestStep actions from the common parsed structure to something that
chip-repl can execute. The responses from the accessory are then
translated back to something the common parser expectes to validate
the response.

* Address PR comments
  • Loading branch information
tehampson authored and pull[bot] committed Jan 25, 2024
1 parent 6fb2f12 commit 9331512
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 954 deletions.
2 changes: 0 additions & 2 deletions scripts/tests/yamltests/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def try_apply_yaml_float_written_as_strings(value):
return value


# TODO(thampson) This method is a clone of the method in
# src/controller/python/chip/yaml/format_converter.py and should eventually be removed in that file.
def convert_yaml_octet_string_to_bytes(s: str) -> bytes:
'''Convert YAML octet string body to bytes.
Expand Down
4 changes: 1 addition & 3 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,10 @@ chip_python_wheel_action("chip-core") {
"chip/utils/CommissioningBuildingBlocks.py",
"chip/utils/__init__.py",
"chip/yaml/__init__.py",
"chip/yaml/constraints.py",
"chip/yaml/data_model_lookup.py",
"chip/yaml/errors.py",
"chip/yaml/format_converter.py",
"chip/yaml/parser.py",
"chip/yaml/variable_storage.py",
"chip/yaml/runner.py",
]

if (chip_controller) {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/yaml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# Provides Python APIs for Matter.

"""Provides yaml parser Python APIs for Matter."""
from . import parser
from . import runner
221 changes: 0 additions & 221 deletions src/controller/python/chip/yaml/constraints.py

This file was deleted.

11 changes: 11 additions & 0 deletions src/controller/python/chip/yaml/data_model_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def get_command(self, cluster: str, command: str):
def get_attribute(self, cluster: str, attribute: str):
pass

@abstractmethod
def get_event(self, cluster: str, event: str):
pass


class PreDefinedDataModelLookup(DataModelLookup):
def get_cluster(self, cluster: str):
Expand All @@ -53,3 +57,10 @@ def get_attribute(self, cluster: str, attribute: str):
return getattr(attributes, attribute, None)
except AttributeError:
return None

def get_event(self, cluster: str, event: str):
try:
events = getattr(Clusters, cluster, None).Events
return getattr(events, event, None)
except AttributeError:
return None
2 changes: 1 addition & 1 deletion src/controller/python/chip/yaml/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, message):
super().__init__(message)


class UnexpectedParsingError(ParsingError):
class UnexpectedParsingError(ValueError):
def __init__(self, message):
super().__init__(message)

Expand Down
Loading

0 comments on commit 9331512

Please sign in to comment.