From 1441154c9fb0908b1812823cff6cac9cb2e317bb Mon Sep 17 00:00:00 2001 From: C Freeman Date: Tue, 31 Oct 2023 19:40:11 -0400 Subject: [PATCH] Python testing: Update print style (#30070) * Python testing: Update print style The json, single-line, no-cluster name thing was making it very hard to fix things, so I changed the print style. * style change * change format of string. --- src/python_testing/matter_testing_support.py | 45 +++++++++++++++++++- src/python_testing/spec_parsing_support.py | 6 +-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 398a01f6cd9d17..759e6cdf377366 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -300,6 +300,18 @@ def get_attribute_string(self, cluster_id: int, attribute_id) -> str: return f"Attribute {attribute_name} ({attribute_id}, 0x{attribute_id:04X})" +def id_str(id): + return f'{id} (0x{id:02x})' + + +def cluster_id_str(id): + if id in Clusters.ClusterObjects.ALL_CLUSTERS.keys(): + s = Clusters.ClusterObjects.ALL_CLUSTERS[id].__name__ + else: + s = "Unknown cluster" + return f'{id_str(id)} {s}' + + @dataclass class AttributePathLocation: endpoint_id: int @@ -319,6 +331,11 @@ def as_string(self, mapper: ClusterMapper): return desc + def __str__(self): + return (f'\n Endpoint: {self.endpoint_id},' + f'\n Cluster: {cluster_id_str(self.cluster_id)},' + f'\n Attribute:{id_str(self.attribute_id)}') + @dataclass class EventPathLocation: @@ -326,6 +343,11 @@ class EventPathLocation: cluster_id: int event_id: int + def __str__(self): + return (f'\n Endpoint: {self.endpoint_id},' + f'\n Cluster: {cluster_id_str(self.cluster_id)},' + f'\n Event: {id_str(self.event_id)}') + @dataclass class CommandPathLocation: @@ -333,12 +355,21 @@ class CommandPathLocation: cluster_id: int command_id: int + def __str__(self): + return (f'\n Endpoint: {self.endpoint_id},' + f'\n Cluster: {cluster_id_str(self.cluster_id)},' + f'\n Command: {id_str(self.command_id)}') + @dataclass class ClusterPathLocation: endpoint_id: int cluster_id: int + def __str__(self): + return (f'\n Endpoint: {self.endpoint_id},' + f'\n Cluster: {cluster_id_str(self.cluster_id)}') + @dataclass class FeaturePathLocation: @@ -346,6 +377,11 @@ class FeaturePathLocation: cluster_id: int feature_code: str + def __str__(self): + return (f'\n Endpoint: {self.endpoint_id},' + f'\n Cluster: {cluster_id_str(self.cluster_id)},' + f'\n Feature: {self.feature_code}') + # ProblemSeverity is not using StrEnum, but rather Enum, since StrEnum only # appeared in 3.11. To make it JSON serializable easily, multiple inheritance # from `str` is used. See https://stackoverflow.com/a/51976841. @@ -365,6 +401,13 @@ class ProblemNotice: problem: str spec_location: str = "" + def __str__(self): + return (f'\nProblem: {str(self.severity)}' + f'\n test_name: {self.test_name}' + f'\n location: {str(self.location)}' + f'\n problem: {self.problem}' + f'\n spec_location: {self.spec_location}\n') + @dataclass class SetupPayloadInfo: @@ -498,7 +541,7 @@ def teardown_class(self): logging.info("Problems found:") logging.info("===============") for problem in self.problems: - logging.info(f"- {json.dumps(dataclass_asdict(problem))}") + logging.info(str(problem)) logging.info("###########################################################") super().teardown_class() diff --git a/src/python_testing/spec_parsing_support.py b/src/python_testing/spec_parsing_support.py index 9e014aa95dd2aa..a2a1a09fafa35c 100644 --- a/src/python_testing/spec_parsing_support.py +++ b/src/python_testing/spec_parsing_support.py @@ -126,11 +126,11 @@ def get_conformance(self, element: ElementTree.Element) -> ElementTree.Element: if element.tag == 'feature': location = FeaturePathLocation(endpoint_id=0, cluster_id=self._cluster_id, feature_code=element.attrib['code']) elif element.tag == 'command': - location = CommandPathLocation(endpoint_id=0, cluster_id=self._cluster_id, command_id=element.attrib['id']) + location = CommandPathLocation(endpoint_id=0, cluster_id=self._cluster_id, command_id=int(element.attrib['id'], 0)) elif element.tag == 'attribute': - location = AttributePathLocation(endpoint_id=0, cluster_id=self._cluster_id, attribute_id=element.attrib['id']) + location = AttributePathLocation(endpoint_id=0, cluster_id=self._cluster_id, attribute_id=int(element.attrib['id'], 0)) elif element.tag == 'event': - location = EventPathLocation(endpoint_id=0, cluster_id=self._cluster_id, event_id=element.attrib['id']) + location = EventPathLocation(endpoint_id=0, cluster_id=self._cluster_id, event_id=int(element.attrib['id'], 0)) else: location = ClusterPathLocation(endpoing_id=0, cluster_id=self._cluster_id) self._problems.append(ProblemNotice(test_name='Spec XML parsing', location=location,