|
20 | 20 | #
|
21 | 21 |
|
22 | 22 | #
|
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. |
24 | 24 | #
|
25 | 25 |
|
26 | 26 | import os
|
27 | 27 | import pytest
|
28 | 28 | import platform
|
29 | 29 |
|
| 30 | +import xml.etree.ElementTree as ET |
| 31 | + |
30 | 32 | from opengrok_tools.utils.xml import insert_file, XMLProcessingException
|
31 | 33 |
|
32 | 34 | DIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
33 | 35 |
|
34 | 36 |
|
35 | 37 | @pytest.mark.skipif(platform.system() == 'Windows',
|
36 | 38 | reason="broken on Windows")
|
| 39 | +@pytest.mark.skipif(not hasattr(ET, "canonicalize"), |
| 40 | + reason="need ElementTree with canonicalize()") |
37 | 41 | def test_xml_insert():
|
38 | 42 | with open(os.path.join(DIR_PATH, "web.xml")) as base_xml:
|
39 | 43 | out = insert_file(base_xml.read(),
|
40 | 44 | 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 |
44 | 51 |
|
45 | 52 |
|
46 | 53 | def test_invalid_xml():
|
|
0 commit comments