File: util.py

package info (click to toggle)
pygml 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 420 kB
  • sloc: python: 5,157; makefile: 15; sh: 5
file content (13 lines) | stat: -rw-r--r-- 679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
def compare_trees(e1, e2):
    # from https://stackoverflow.com/a/24349916/746961
    if e1.tag != e2.tag:
        raise AssertionError(f'Tag: {e1.tag} != {e2.tag}')
    if (e1.text or '').strip() != (e2.text or '').strip():
        raise AssertionError(f'Text: {e1.text} != {e2.text}')
    if (e1.tail or '').strip() != (e2.tail or '').strip():
        raise AssertionError(f'Tail: {e1.tail} != {e2.tail}')
    if e1.attrib != e2.attrib:
        raise AssertionError(f'Attributes: {e1.attrib} != {e2.attrib}')
    if len(e1) != len(e2):
        raise AssertionError(f'Child nodes: {len(e1.tag)} != {len(e2.tag)}')
    return all(compare_trees(c1, c2) for c1, c2 in zip(e1, e2))