contains_xml method#177
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #177 +/- ##
==========================================
+ Coverage 98.63% 98.64% +0.01%
==========================================
Files 11 11
Lines 1745 1754 +9
Branches 167 168 +1
==========================================
+ Hits 1721 1730 +9
Misses 5 5
Partials 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| def contains_xml(self, verify: bool = False) -> bool: | ||
| """ | ||
| Check if the message contains any XML tags. | ||
|
|
||
| :param verify: verify if the XML structure is well-formed | ||
| """ | ||
| message = self.render(render_format=RenderFormat.STRING, show_warning=False) | ||
| wrapped = "<root>{message}</root>".format(message=message) | ||
| pattern_result = bool(re.search(XML_PATTERN, message)) | ||
| if not verify: | ||
| return pattern_result | ||
| try: | ||
| _ = ElementTree.fromstring(wrapped) | ||
| return pattern_result | ||
| except Exception: | ||
| return False |
There was a problem hiding this comment.
I believe contains_xml should always detect the variable XMLs in the message. This new method is a smarter way to detect whether XML is present in the text. So my suggestion is to remove the verify parameter and assume it's always True.
There was a problem hiding this comment.
It is very common for the structure of XML to be wrong, especially in responses. It is important for users to recognize that the response contains XML tags, but is not well-formed, so they can retry or take other actions.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
verifyparameter added tocontains_xmlmethodAny other comments?