summaryrefslogtreecommitdiff
path: root/tests/support/structural_diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/support/structural_diff.py')
-rw-r--r--tests/support/structural_diff.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/support/structural_diff.py b/tests/support/structural_diff.py
new file mode 100644
index 00000000..d2e4d7f2
--- /dev/null
+++ b/tests/support/structural_diff.py
@@ -0,0 +1,17 @@
+import lxml.html
+import lxml.etree
+import pytest
+
+def _serialize(t):
+ for a, e in lxml.etree.iterwalk(t, events=("start", "end"),):
+ text = e.text.strip() if e.text else ""
+ yield (a, e.tag, repr(text), ', '.join([k[0]+':'+k[1] for k in sorted(e.attrib.items(), key = lambda x: x[0])]))
+
+def structural_diff(a, b):
+ """Check if there is a structural difference between two HTML files."""
+ a_s = _serialize(lxml.html.fromstring(a))
+ b_s = _serialize(lxml.html.fromstring(b))
+
+ for e, f in zip(a_s, b_s):
+ print(e, f)
+ assert e == f \ No newline at end of file