INNER CODE UNIT · Python
compare_elements
usnistgov/OSCAL · src/specifications/profile-resolution/spec-tester.py:162
def compare_elements(e1: Optional[ET.ElementTree], e2: Optional[ET.ElementTree], path=".",
e1Name="left", e2Name="right") -> Tuple[bool, List[str]]:
"""
Compare two element trees returning if they are the same, and a list of changes in the form of
XPath-like selections.
Warning: This comparison function will likely fail on mixed content (e.g. markup) and in cases
where the order of child elements is different.
Note: comments added to some difference paths using XPath 2.0 (: comment syntax :)
"""
differences: List[str] = []
if e1 is None:
differences.append(
f"{path}/ (: tag mismatch: {e1Name}=None {e2Name}='{e2.tag}' :)")
elif e2 is None: