From 055bbb4e2fc272091a6e2709636ca50a93226394 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 27 Jan 2023 10:21:22 -0500 Subject: [PATCH] chip-repl tests: xml parsing to report location of where unrecognized handlers reside (#24674) * Report location of where unrecognized handlers reside * Restyle --- .../matter_idl/zapxml/__init__.py | 7 ++++--- .../matter_idl/zapxml/handlers/context.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/py_matter_idl/matter_idl/zapxml/__init__.py b/scripts/py_matter_idl/matter_idl/zapxml/__init__.py index 41b31b452ae066..519307f298bf4a 100644 --- a/scripts/py_matter_idl/matter_idl/zapxml/__init__.py +++ b/scripts/py_matter_idl/matter_idl/zapxml/__init__.py @@ -15,12 +15,11 @@ import logging import typing import xml.sax.handler - from dataclasses import dataclass -from typing import Optional, Union, List +from typing import List, Optional, Union -from matter_idl.zapxml.handlers import Context, ZapXmlHandler from matter_idl.matter_idl_types import Idl +from matter_idl.zapxml.handlers import Context, ZapXmlHandler class ParseHandler(xml.sax.handler.ContentHandler): @@ -50,6 +49,8 @@ def PrepareParsing(self, filename): if self._include_meta_data: self._idl.parse_file_name = filename + self._context.file_name = filename + def Finish(self) -> Idl: self._context.PostProcess(self._idl) return self._idl diff --git a/scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py b/scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py index c4f4f4094fbcc8..c25c7b77c26fce 100644 --- a/scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py +++ b/scripts/py_matter_idl/matter_idl/zapxml/handlers/context.py @@ -81,6 +81,7 @@ class Context: def __init__(self, locator: Optional[xml.sax.xmlreader.Locator] = None): self.path = ProcessingPath() self.locator = locator + self.file_name = None self._not_handled = set() self._idl_post_processors = [] @@ -93,6 +94,15 @@ def GetCurrentLocationMeta(self) -> ParseMetaData: return ParseMetaData(line=self.locator.getLineNumber(), column=self.locator.getColumnNumber()) + def ParseLogLocation(self) -> Optional[str]: + if not self.file_name: + return None + meta = self.GetCurrentLocationMeta() + if not meta: + return None + + return f"{self.file_name}:{meta.line}:{meta.column}" + def GetGlobalAttribute(self, code): if code in self._global_attributes: return self._global_attributes[code] @@ -112,7 +122,13 @@ def AddGlobalAttribute(self, attribute: Attribute): def MarkTagNotHandled(self): path = str(self.path) if path not in self._not_handled: - logging.warning("TAG %s was not handled/recognized" % path) + msg = "TAG %s was not handled/recognized" % path + + where = self.ParseLogLocation() + if where: + msg = msg + " at " + where + + logging.warning(msg) self._not_handled.add(path) def AddIdlPostProcessor(self, processor: IdlPostProcessor):