diff options
author | Stephanie Marcu <stephanie.marcu@logilab.fr> | 2008-11-18 11:17:58 +0100 |
---|---|---|
committer | Stephanie Marcu <stephanie.marcu@logilab.fr> | 2008-11-18 11:17:58 +0100 |
commit | 8eefcf50468679bc654a6aadc765c5f6dbf0a4c9 (patch) | |
tree | 901a411e8b2b2e453364934f844b92b5a0981741 | |
parent | 1a784686f57b682860ced2192ca1c9c5fa0ec520 (diff) | |
download | logilab-common-8eefcf50468679bc654a6aadc765c5f6dbf0a4c9.tar.gz |
add a method to test equality between two floats
-rw-r--r-- | testlib.py | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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 |