From d69daab39f322b7b3c75a7c4df2260f56c826f60 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 4 Sep 2015 17:34:26 -0400 Subject: [PATCH] [Test] Fix error in test comparison when numbers disappear --- site_scons/buildutils.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index b14f37454..6d528b64f 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -236,15 +236,20 @@ def compareTextFiles(env, file1, file2): # String representations match, so replacement is unnecessary continue - delta = max(getPrecision(floats1[j][1]), getPrecision(floats2[j][1])) - num1 = float(floats1[j][1]) - num2 = float(floats2[j][1]) - abserr = abs(num1-num2) - relerr = abserr / (0.5 * abs(num1 + num2) + atol) - if abserr > (1.1*delta + atol) and relerr > rtol: - print 'Values differ: {0: 14g} {1: 14g}; rel. err = {2:.3e}; abs. err = {3:.3e}'.format(num1, num2, relerr, abserr) - allMatch = False - break + try: + delta = max(getPrecision(floats1[j][1]), getPrecision(floats2[j][1])) + num1 = float(floats1[j][1]) + num2 = float(floats2[j][1]) + abserr = abs(num1-num2) + relerr = abserr / (0.5 * abs(num1 + num2) + atol) + if abserr > (1.1*delta + atol) and relerr > rtol: + print 'Values differ: {0: 14g} {1: 14g}; rel. err = {2:.3e}; abs. err = {3:.3e}'.format(num1, num2, relerr, abserr) + allMatch = False + break + except Exception as e: + # Something went wrong -- one of the strings isn't actually a number, + # so just ignore this line and let the test fail + pass # All the values are sufficiently close, so replace the string # so that the diff of this line will succeed