Skip to content

Commit 35bcf1d

Browse files
committed
IDM-12.1: Also dump to log
1 parent b367512 commit 35bcf1d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/python_testing/TC_DeviceBasicComposition.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,17 @@ def test_TC_IDM_12_1(self):
775775
software_version = self.endpoints[0][Clusters.BasicInformation][Clusters.BasicInformation.Attributes.SoftwareVersion]
776776
filename = f'device_dump_0x{vid:04X}_0x{pid:04X}_{software_version}.json'
777777
dump_device_composition_path = self.user_params.get("dump_device_composition_path", filename)
778-
self.dump_wildcard(dump_device_composition_path)
778+
json_str, txt_str = self.dump_wildcard(dump_device_composition_path)
779+
780+
# Structured dump so we can pull these back out of the logs
781+
def log_structured_data(start_tag: str, dump_string):
782+
lines = dump_string.splitlines(keepends=True)
783+
logging.info(f'{start_tag}BEGIN ({len(lines)} lines)====')
784+
logging.info(f'{start_tag}{start_tag.join(lines)}')
785+
logging.info(f'{start_tag}END ====')
786+
787+
log_structured_data('==== json: ', json_str)
788+
log_structured_data('==== txt: ', txt_str)
779789

780790

781791
if __name__ == "__main__":

src/python_testing/basic_composition_support.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import pathlib
2424
import sys
2525
import typing
26-
from pprint import pprint
26+
from pprint import pformat, pprint
2727
from typing import Any, Optional
2828

2929
import chip.clusters.ClusterObjects
@@ -105,15 +105,20 @@ async def connect_over_pase(self, dev_ctrl):
105105
asserts.assert_equal(len(setupCode), 1, "Require one of either --qr-code or --manual-code.")
106106
await dev_ctrl.FindOrEstablishPASESession(setupCode[0], self.dut_node_id)
107107

108-
def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]):
108+
def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]) -> tuple[str, str]:
109+
""" Dumps a json and a txt file of the attribute wildcard for this device if the dump_device_composition_path is supplied.
110+
Returns the json and txt as strings.
111+
"""
109112
node_dump_dict = {endpoint_id: MatterTlvToJson(self.endpoints_tlv[endpoint_id]) for endpoint_id in self.endpoints_tlv}
110-
logging.debug(f"Raw TLV contents of Node: {json.dumps(node_dump_dict, indent=2)}")
113+
json_dump_string = json.dumps(node_dump_dict, indent=2)
114+
logging.debug(f"Raw TLV contents of Node: {json_dump_string}")
111115

112116
if dump_device_composition_path is not None:
113117
with open(pathlib.Path(dump_device_composition_path).with_suffix(".json"), "wt+") as outfile:
114118
json.dump(node_dump_dict, outfile, indent=2)
115119
with open(pathlib.Path(dump_device_composition_path).with_suffix(".txt"), "wt+") as outfile:
116120
pprint(self.endpoints, outfile, indent=1, width=200, compact=True)
121+
return (json_dump_string, pformat(self.endpoints, indent=1, width=200, compact=True))
117122

118123
async def setup_class_helper(self, default_to_pase: bool = True):
119124
dev_ctrl = self.default_controller

0 commit comments

Comments
 (0)