Skip to content

Commit 09ce59a

Browse files
pcaspersjenkins
authored andcommitted
QPR-12014 comapre xml files using xmldiff, make deliberate change to expected result to test the xml diff tool
1 parent 986cd6c commit 09ce59a

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

Docker/Dockerfile-Test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN apt-get update \
55
&& DEBIAN_FRONTEND=noninteractive apt-get install -y dos2unix python3 python3-pip libxml2-utils xsltproc \
66
&& apt-get clean \
77
&& rm -rf /var/lib/apt/lists/* \
8-
&& pip3 install matplotlib pandas nose nose_xunitmp datacompy jsondiff lxml
8+
&& pip3 install matplotlib pandas nose nose_xunitmp datacompy jsondiff lxml xmldiff
99

1010
CMD bash
1111

Tools/PythonTools/compare_files.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from datacompy.core import Compare
1212
import re
1313
import jsondiff
14+
from lxml import etree
15+
from xmldiff import main, formatting
1416

1517

1618
def is_float(num: str):
@@ -253,10 +255,11 @@ def compare_files(file_1, file_2, name, config: dict = None) -> bool:
253255
raise ValueError('File, ' + file_1 + ', requires a comparison configuration but none given.')
254256
if ext_2 == '.csv':
255257
raise ValueError('File, ' + file_2 + ', requires a comparison configuration but none given.')
256-
257-
if comp_config is None:
258-
# If there was no configuration then fall back to a straight file comparison.
259-
result = compare_files_direct(name, file_1, file_2)
258+
if ext_1 == '.xml' and ext_2 == '.xml':
259+
result = compare_files_xml(name, file_1, file_2)
260+
else:
261+
# If there was no configuration then fall back to a straight file comparison.
262+
result = compare_files_direct(name, file_1, file_2)
260263
else:
261264
config_type = comp_config.get('type')
262265
if config_type == 'csv':
@@ -549,6 +552,15 @@ def compare_files_direct(name, file_1, file_2):
549552

550553
return match
551554

555+
def compare_files_xml(name, file_1, file_2):
556+
logger = logging.getLogger(__name__)
557+
logger.debug('%s: Comparing file %s against %s using xml diff', name, file_1, file_2)
558+
diff = main.diff_files('file1.xml', 'file2.xml', formatter=formatting.XMLFormatter())
559+
match = True
560+
for line in diff:
561+
match = False
562+
logger.warning(line.rstrip('\n'))
563+
return match
552564

553565
def compare_files_json(name, file_1, file_2, config) -> bool:
554566
# Compare JSON files using configuration.

0 commit comments

Comments
 (0)