2016-11-08 18:57:35 +01:00
|
|
|
|
2016-11-11 18:41:43 +01:00
|
|
|
|
|
|
|
|
def isclose(value1,value2,error_tolerance=1e-2):
|
2016-11-12 16:56:50 +01:00
|
|
|
""" This is used to compare relative values. """
|
2016-11-11 18:41:43 +01:00
|
|
|
import debug
|
|
|
|
|
relative_diff = abs(value1 - value2) / max(value1,value2)
|
|
|
|
|
check = relative_diff <= error_tolerance
|
|
|
|
|
if not check:
|
2016-11-11 19:04:09 +01:00
|
|
|
debug.info(1,"NOT CLOSE {0} {1} relative diff={2}".format(value1,value2,relative_diff))
|
2016-11-11 18:41:43 +01:00
|
|
|
else:
|
|
|
|
|
debug.info(2,"CLOSE {0} {1} relative diff={2}".format(value1,value2,relative_diff))
|
|
|
|
|
return (check)
|
|
|
|
|
|
2016-11-12 16:56:50 +01:00
|
|
|
def isdiff(file1,file2):
|
|
|
|
|
""" This is used to compare two files and display the diff if they are different.. """
|
|
|
|
|
import debug
|
|
|
|
|
import filecmp
|
|
|
|
|
import difflib
|
2016-11-12 20:16:08 +01:00
|
|
|
check = filecmp.cmp(file1,file2)
|
2016-11-12 16:56:50 +01:00
|
|
|
if not check:
|
|
|
|
|
debug.info(2,"MISMATCH {0} {1}".format(file1,file2))
|
|
|
|
|
f1 = open(file1,"r")
|
|
|
|
|
s1 = f1.readlines()
|
|
|
|
|
f2 = open(file2,"r")
|
|
|
|
|
s2 = f2.readlines()
|
2016-11-12 20:16:08 +01:00
|
|
|
for line in difflib.unified_diff(s1, s2):
|
2016-11-12 16:56:50 +01:00
|
|
|
debug.error(line)
|
|
|
|
|
else:
|
|
|
|
|
debug.info(2,"MATCH {0} {1}".format(file1,file2))
|
|
|
|
|
return (check)
|
|
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
def header(str, tec):
|
|
|
|
|
tst = "Running Test for:"
|
|
|
|
|
print "\n"
|
|
|
|
|
print " ______________________________________________________________________________ "
|
|
|
|
|
print "|==============================================================================|"
|
|
|
|
|
print "|=========" + tst.center(60) + "=========|"
|
|
|
|
|
print "|=========" + tec.center(60) + "=========|"
|
|
|
|
|
print "|=========" + str.center(60) + "=========|"
|
|
|
|
|
print "|==============================================================================|"
|