summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephanie Marcu <stephanie.marcu@logilab.fr>2008-11-18 11:17:58 +0100
committerStephanie Marcu <stephanie.marcu@logilab.fr>2008-11-18 11:17:58 +0100
commit8eefcf50468679bc654a6aadc765c5f6dbf0a4c9 (patch)
tree901a411e8b2b2e453364934f844b92b5a0981741
parent1a784686f57b682860ced2192ca1c9c5fa0ec520 (diff)
downloadlogilab-common-8eefcf50468679bc654a6aadc765c5f6dbf0a4c9.tar.gz
add a method to test equality between two floats
-rw-r--r--testlib.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/testlib.py b/testlib.py
index e45e9b6..7f4e9d2 100644
--- a/testlib.py
+++ b/testlib.py
@@ -38,6 +38,7 @@ import unittest
import difflib
import types
import tempfile
+import math
from shutil import rmtree
from operator import itemgetter
from warnings import warn
@@ -1592,6 +1593,12 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
if msg is None:
msg = "unexpected reference to None"
self.assert_( obj is not None, msg )
+
+ def assertFloatEquals(self, obj, other, prec=1e-5, msg=None):
+ """compares two floats"""
+ if msg is None:
+ msg = "%r != %r" % (obj, other)
+ self.assert_(math.fabs(obj - other) < prec)
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
"""override default failUnlessRaise method to return the raised