]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: fix tests around XML by canonicalizing XML representation
authorVincent Bernat <vincent@bernat.ch>
Mon, 7 Sep 2020 18:10:10 +0000 (20:10 +0200)
committerVincent Bernat <vincent@bernat.ch>
Mon, 7 Sep 2020 18:10:10 +0000 (20:10 +0200)
Since Python 3.8, insertion order is respected for attributes, so we
cannot just compare strings as previously. Python 3.8 also introduces
a `canonicalize()` function to normalize XML for digital signature. We
apply this function if it exists.

tests/integration/test_lldpcli.py

index 6a9ee801890d38ccc0fc3b2569867b48a76b89f7..1d1da2e82f921154e9b0fb200a9f6a24a86d39ad 100644 (file)
@@ -6,6 +6,12 @@ import platform
 import json
 import xml.etree.ElementTree as ET
 
+if hasattr(ET, "canonicalize"):
+    canonicalize = ET.canonicalize
+else:
+    def canonicalize(x):
+        x
+
 
 @pytest.fixture(scope='session')
 def uname():
@@ -342,7 +348,7 @@ def test_xml_output(request, lldpd1, lldpd, lldpcli, namespaces, uname,
                                                  station=station,
                                                  uname=uname,
                                                  dot3=dot3))
-        assert ET.tostring(xml) == ET.tostring(expected)
+        assert canonicalize(ET.tostring(xml)) == canonicalize(ET.tostring(expected))
 
 
 @pytest.mark.skipif("'Dot3' not in config.lldpd.features",
@@ -518,7 +524,7 @@ def test_watch_xml(lldpd1, lldpd, lldpcli, namespaces, links):
         got = result.stdout.decode('ascii')
         got = ET.fromstring(got)
         got.find('./interface').set('age', '')
-        assert ET.tostring(got) == ET.tostring(expected)
+        assert canonicalize(ET.tostring(got)) == canonicalize(ET.tostring(expected))
 
 
 @pytest.mark.skipif("'JSON' not in config.lldpcli.outputs",