Skip to content

Commit

Permalink
Python testing: Update print style (#30070)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
cecille authored and pull[bot] committed Jan 18, 2024
1 parent 871aea2 commit aa4efa1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
45 changes: 44 additions & 1 deletion src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -319,33 +331,57 @@ 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:
endpoint_id: int
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:
endpoint_id: int
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:
endpoint_id: int
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.
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/python_testing/spec_parsing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aa4efa1

Please sign in to comment.