Skip to content

Commit

Permalink
Merge pull request #1951 from joshua-cogliati-inl/xml_alt_root
Browse files Browse the repository at this point in the history
Allows XML diff to only check a specific node.
  • Loading branch information
dylanjm authored Sep 1, 2022
2 parents 0bba111 + 29457d2 commit 712df94
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
24 changes: 22 additions & 2 deletions rook/XMLDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,20 @@ def diff(self):
files_read = False
self.__messages += 'Exception reading file '+gold_filename+': '+str(exp.args)
if files_read:
if 'unordered' in self.__options.keys() and self.__options['unordered']:
if self.__options['alt_root'] is not None:
alt_test_root_list = test_root.findall(self.__options['alt_root'])
alt_gold_root_list = gold_root.findall(self.__options['alt_root'])
if len(alt_test_root_list) != 1 or len(alt_gold_root_list) != 1:
self.__same = False
messages = ["Alt root used and test len "+str(len(alt_test_root_list))+
" and gold len "+str(len(alt_gold_root_list))]
same = False
else:
test_root = alt_test_root_list[0]
gold_root = alt_gold_root_list[0]
if not self.__same:
pass #already failed
elif 'unordered' in self.__options.keys() and self.__options['unordered']:
same, messages = compare_unordered_element(gold_root, test_root, **self.__options)
else:
same, messages = compare_ordered_element(test_root, gold_root, **self.__options)
Expand Down Expand Up @@ -441,7 +454,10 @@ def get_valid_params():
params.add_param('remove_unicode_identifier', False,
'if true, then remove u infront of a single quote')
params.add_param('xmlopts', '', "Options for xml checking")
params.add_param('rel_err', '', 'Relative Error for csv files or floats in xml ones')
params.add_param('rel_err', '',
'Relative Error for csv files or floats in xml ones')
params.add_param('alt_root', '', 'If included, do a findall on the value on the root,'+
' and then use that as the root instead. Note, findall must return one value')
return params

def __init__(self, name, params, test_dir):
Expand All @@ -462,6 +478,10 @@ def __init__(self, name, params, test_dir):
self.__xmlopts['remove_unicode_identifier'] = self.specs['remove_unicode_identifier']
if len(self.specs['xmlopts']) > 0:
self.__xmlopts['xmlopts'] = self.specs['xmlopts'].split(' ')
if len(self.specs['alt_root']) > 0:
self.__xmlopts['alt_root'] = self.specs['alt_root']
else:
self.__xmlopts['alt_root'] = None

def check_output(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
check_errors/revirD_tset/
reg_self_tests/text_test.txt
reg_self_tests/text_test2.txt
reg_self_tests/text_test2.txt
reg_self_tests/a_xml_file.xml
11 changes: 11 additions & 0 deletions tests/reg_self_tests/create_xml_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

open("a_xml_file.xml", "w").write("""
<root>
<matching>
<inside/>
</matching>
<mismatch>
<not_the_same/>
</mismatch>
</root>
""")
8 changes: 8 additions & 0 deletions tests/reg_self_tests/gold/a_xml_file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<root>
<matching>
<inside/>
</matching>
<mismatch>
<a_diffrent_thing/>
</mismatch>
</root>
11 changes: 11 additions & 0 deletions tests/reg_self_tests/tests
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@
rel_err = 1.0e-4
[../]
[../]
[./xml_check]
type = 'GenericExecutable'
executable = 'python'
parameters = 'create_xml_file.py'
[./xml]
type = XML
unordered = true
output = a_xml_file.xml
alt_root = './matching'
[../]
[../]
[]

0 comments on commit 712df94

Please sign in to comment.