Skip to content

Commit

Permalink
Small change added filename and string variable. (#94)
Browse files Browse the repository at this point in the history
Compare_xml produces result string and file
  • Loading branch information
mwuetschner authored and fariza committed Sep 28, 2016
1 parent 7dc1c23 commit 18eab7e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions emva1288/process/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,39 +418,39 @@ def round_significant(v, sig=SIGNIFICANT_DIGITS):
round_array = np.vectorize(round_significant)


def compare_xml(x1, x2):
def compare_xml(x1, x2, filename=None):
# load the xml into dicts
f1 = xml_to_dict(x1)
f2 = xml_to_dict(x2)
s = ''

# if something is wrong abort
if f1 is None or f2 is None:
return
return s

c1 = list(f1.keys())
c2 = list(f2.keys())

# loop throught the combined categories
categories = set(c1) | set(c2)
for category in sorted(categories):
print('')
print('*' * 70)
print(category)
print('*' * 70)
s += '*' * 70 + '\n'
s += category + '\n'
s += '*' * 70 + '\n'
# check if missing category in one of the dicts
if category not in c1 or category not in c2:
t1 = category in c1
t2 = category in c2
print('{0:<35}'.format('PRESENT'), end=" ")
print('{0:<20}{1:<20}FAIL'.format(str(t1), str(t2)))
s += '{0:<35}'.format('PRESENT')
s += '{0:<20}{1:<20}FAIL'.format(str(t1), str(t2)) + '\n'
continue

m1 = f1[category].keys()
m2 = f2[category].keys()
# loop throught the combined methodnames
methodnames = set(m1) | set(m2)
for methodname in sorted(methodnames):
print('{0:<35}'.format(methodname), end=" ")
s += '{0:<35}'.format(methodname)

# check if methodname in dict
if methodname not in m1:
Expand Down Expand Up @@ -505,8 +505,16 @@ def compare_xml(x1, x2):
t2 = str(v2)
r = False

print('{0:<20}{1:<20}'.format(t1, t2), end=" ")
s += '{0:<20}{1:<20}'.format(t1, t2)
if r:
print('OK')
s += 'OK' + '\n'
else:
print('FAIL')
s += 'FAIL' + '\n'

s += '\n'

if filename is None:
return s
with open(filename, 'w') as f:
f.write(s)
return s

0 comments on commit 18eab7e

Please sign in to comment.