From: Vincent Bernat Date: Mon, 7 Sep 2020 18:10:10 +0000 (+0200) Subject: tests: fix tests around XML by canonicalizing XML representation X-Git-Tag: 1.0.7~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d06c55cab1eea7e825e5ac65f951f2ca0e0d4e5;p=thirdparty%2Flldpd.git tests: fix tests around XML by canonicalizing XML representation 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. --- diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 6a9ee801..1d1da2e8 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -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",