Skip to content

Commit 8d5643d

Browse files
author
Vladimir Kotal
committed
compare canonical XML representations in test_xml_insert()
fixes #3739
1 parent 067f2ef commit 8d5643d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/src/test/python/test_xml.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,34 @@
2020
#
2121

2222
#
23-
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
23+
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2424
#
2525

2626
import os
2727
import pytest
2828
import platform
2929

30+
import xml.etree.ElementTree as ET
31+
3032
from opengrok_tools.utils.xml import insert_file, XMLProcessingException
3133

3234
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
3335

3436

3537
@pytest.mark.skipif(platform.system() == 'Windows',
3638
reason="broken on Windows")
39+
@pytest.mark.skipif(not hasattr(ET, "canonicalize"),
40+
reason="need ElementTree with canonicalize()")
3741
def test_xml_insert():
3842
with open(os.path.join(DIR_PATH, "web.xml")) as base_xml:
3943
out = insert_file(base_xml.read(),
4044
os.path.join(DIR_PATH, "insert.xml"))
41-
with open(os.path.join(DIR_PATH, "new.xml")) as expected_xml:
42-
# TODO: this should really be comparing XML trees
43-
assert out.strip() == expected_xml.read().strip()
45+
with open(os.path.join(DIR_PATH, "new.xml")) as expected_xml_fp:
46+
out_xml_canonical = ET.canonicalize(out, strip_text=True)
47+
expected_xml_canonical = ET.canonicalize(from_file=expected_xml_fp,
48+
strip_text=True)
49+
50+
assert out_xml_canonical == expected_xml_canonical
4451

4552

4653
def test_invalid_xml():

0 commit comments

Comments
 (0)