Skip to content

Commit

Permalink
Adjusting the text compare to ignore whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Jun 11, 2019
1 parent e15bce8 commit 71d9921
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions build/ci-cd/python/xmlComparison.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# imports
import sys
import re
from lxml import etree
from printColors import bcolors

Expand Down Expand Up @@ -35,7 +36,11 @@ def compareElements(e1, e2, xpath, position):
print(bcolors.FAIL + "Different attribute values at path: "+xpath+"/@"+ attrKey + bcolors.ENDC)
retval = False
# check text
if e1.text != e2.text:
xstr = lambda s: s or ""
pattern = "\s+"
text1 = re.sub(pattern, xstr(e1.text), "")
text2 = re.sub(pattern, xstr(e2.text), "")
if text1 != text2:
print(bcolors.FAIL + "Different text at path: "+xpath+"/text()" + bcolors.ENDC)
retval = False

Expand Down Expand Up @@ -68,8 +73,9 @@ def compareElements(e1, e2, xpath, position):
xml2 = sys.argv[2]

# parse the documents
doc1 = etree.parse(xml1)
doc2 = etree.parse(xml2)
parser = etree.XMLParser(remove_comments=True,remove_blank_text=True,collect_ids=False)
doc1 = etree.parse(xml1, parser)
doc2 = etree.parse(xml2, parser)

# get the root element
root1 = doc1.getroot()
Expand Down
2 changes: 1 addition & 1 deletion build/ci-cd/validate-round-trips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ while IFS="|" read path format model converttoformats || [[ -n "$path" ]]; do
fi

# compare the XML files to see if there is data loss
echo "${P_INFO}Checking XML->JSON->XML conversion for '${P_END}${file}${P_ERROR}'.${P_END}\n"
echo "${P_INFO}Checking XML->JSON->XML conversion for '${P_END}${file}${P_ERROR}'.${P_END}"
python ${OSCALDIR}/build/ci-cd/python/xmlComparison.py "$back_to_xml" "$file"
cmd_exitcode=$?
if [ $cmd_exitcode != 0 ]; then
Expand Down

0 comments on commit 71d9921

Please sign in to comment.