Skip to content

Commit

Permalink
Python testing: Update print style
Browse files Browse the repository at this point in the history
The json, single-line, no-cluster name thing was making it very
hard to fix things, so I changed the print style.
  • Loading branch information
cecille committed Oct 27, 2023
1 parent b3c844b commit 80c0cab
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
49 changes: 48 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,26 @@ def get_attribute_string(self, cluster_id: int, attribute_id) -> str:
return f"Attribute {attribute_name} ({attribute_id}, 0x{attribute_id:04X})"


@dataclass
class ID:
id: int

def __str__(self):
return f'{self.id} (0x{self.id:02x})'


@dataclass
class ClusterID:
id: int

def __str__(self):
if self.id in Clusters.ClusterObjects.ALL_CLUSTERS.keys():
s = Clusters.ClusterObjects.ALL_CLUSTERS[self.id].__name__
else:
s = "Unknown cluster"
return f'{str(ID(self.id))} {s}'


@dataclass
class AttributePathLocation:
endpoint_id: int
Expand All @@ -319,33 +339,57 @@ def as_string(self, mapper: ClusterMapper):

return desc

def __str__(self):
return (f'\n Endpoint: {self.endpoint_id},'
f'\n Cluster: {str(ClusterID(self.cluster_id))},'
f'\n Attribute:{str(ID(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: {str(ClusterID(self.cluster_id))},'
f'\n Event: {str(ID(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: {str(ClusterID(self.cluster_id))},'
f'\n Command: {str(ID(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: {str(ClusterID(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: {str(ClusterID(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 +409,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 +545,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(lement.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 80c0cab

Please sign in to comment.