summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Chauve <adrien.chauve@logilab.fr>2010-07-29 17:53:41 +0200
committerAdrien Chauve <adrien.chauve@logilab.fr>2010-07-29 17:53:41 +0200
commite770ad09f3ae646b823d6275192f4c8290885d42 (patch)
treed758f6f02c7c14bdc196912af18a2846084ac9d8
parentfac3eabf729f6e7a8b93bd0e8cc1b252ea2a3fba (diff)
downloadlogilab-common-e770ad09f3ae646b823d6275192f4c8290885d42.tar.gz
[testlib] add relative tolerance to assertFloatAlmostEquals
-rw-r--r--testlib.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/testlib.py b/testlib.py
index 4cd2b0c..1a7bad6 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1039,18 +1039,20 @@ succeeded test into", osp.join(os.getcwd(), FILE_RESTART)
self.assert_( obj is not None, msg )
@deprecated('Non-standard. Please use assertAlmostEqual instead.')
- def assertFloatAlmostEquals(self, obj, other, prec=1e-5, msg=None):
+ def assertFloatAlmostEquals(self, obj, other, prec=1e-5,
+ relative_prec=1e-5, msg=None):
"""compares if two floats have a distance smaller than expected
precision.
:param obj: a Float
:param other: another Float to be comparted to <obj>
:param prec: a Float describing the precision
+ :param relative_prec: a Float describing the relative precision
:param msg: a String for a custom message
"""
if msg is None:
msg = "%r != %r" % (obj, other)
- self.assert_(math.fabs(obj - other) < prec, msg)
+ self.assert_(math.fabs(obj - other) < prec+relative_prec*math.fabs(obj), msg)
#@deprecated('[API] Non-standard. Please consider using a context here')
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):