Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python testing: Update print style #30070

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 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,9 @@ class ProblemNotice:
problem: str
spec_location: str = ""

def __str__(self):
return f'\nProblem: {str(self.severity)}\n test_name: {self.test_name}\n location: {str(self.location)}\n problem: {self.problem}\n spec_location: {self.spec_location}\n'


@dataclass
class SetupPayloadInfo:
Expand Down Expand Up @@ -498,7 +537,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