diff options
author | Eli Bendersky <eliben@gmail.com> | 2011-02-25 10:14:17 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2011-02-25 10:14:17 (GMT) |
commit | 67ebabd1527d7b461ed6a4e853e100a19751368b (patch) | |
tree | 6e8f86933518d68ea83dda12caf22857df4b3dc3 /Lib | |
parent | cbbaa96036b8467c21f2c7127a3711fcb405d00f (diff) | |
download | cpython-67ebabd1527d7b461ed6a4e853e100a19751368b.zip cpython-67ebabd1527d7b461ed6a4e853e100a19751368b.tar.gz cpython-67ebabd1527d7b461ed6a4e853e100a19751368b.tar.bz2 |
Removed fcmp and FUZZ from test.support, following the discussion on python-dev:
http://mail.python.org/pipermail/python-dev/2011-January/107735.html
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/support.py | 20 | ||||
-rw-r--r-- | Lib/test/test_builtin.py | 13 | ||||
-rw-r--r-- | Lib/test/test_float.py | 2 |
3 files changed, 10 insertions, 25 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 63c5569..7e544fc 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -33,7 +33,7 @@ __all__ = [ "verbose", "use_resources", "max_memuse", "record_original_stdout", "get_original_stdout", "unload", "unlink", "rmtree", "forget", "is_resource_enabled", "requires", "find_unused_port", "bind_port", - "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "SAVEDCWD", "temp_cwd", + "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd", "findfile", "sortdict", "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", "captured_output", "captured_stdout", @@ -349,24 +349,6 @@ def bind_port(sock, host=HOST): port = sock.getsockname()[1] return port -FUZZ = 1e-6 - -def fcmp(x, y): # fuzzy comparison function - if isinstance(x, float) or isinstance(y, float): - try: - fuzz = (abs(x) + abs(y)) * FUZZ - if abs(x-y) <= fuzz: - return 0 - except: - pass - elif type(x) == type(y) and isinstance(x, (tuple, list)): - for i in range(min(len(x), len(y))): - outcome = fcmp(x[i], y[i]) - if outcome != 0: - return outcome - return (len(x) > len(y)) - (len(x) < len(y)) - return (x > y) - (x < y) - # decorator for skipping tests on non-IEEE 754 platforms requires_IEEE_754 = unittest.skipUnless( float.__getformat__("double").startswith("IEEE"), diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 1469e36..61d4046 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -10,7 +10,7 @@ import ast import types import builtins import random -from test.support import fcmp, TESTFN, unlink, run_unittest, check_warnings +from test.support import TESTFN, unlink, run_unittest, check_warnings from operator import neg @@ -394,10 +394,13 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(divmod(-sys.maxsize-1, -1), (sys.maxsize+1, 0)) - self.assertTrue(not fcmp(divmod(3.25, 1.0), (3.0, 0.25))) - self.assertTrue(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75))) - self.assertTrue(not fcmp(divmod(3.25, -1.0), (-4.0, -0.75))) - self.assertTrue(not fcmp(divmod(-3.25, -1.0), (3.0, -0.25))) + for num, denom, exp_result in [ (3.25, 1.0, (3.0, 0.25)), + (-3.25, 1.0, (-4.0, 0.75)), + (3.25, -1.0, (-4.0, -0.75)), + (-3.25, -1.0, (3.0, -0.25))]: + result = divmod(num, denom) + self.assertAlmostEqual(result[0], exp_result[0]) + self.assertAlmostEqual(result[1], exp_result[1]) self.assertRaises(TypeError, divmod) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 30cb4b9..72a2643 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -88,7 +88,7 @@ class GeneralFloatCases(unittest.TestCase): self.assertRaises(ValueError, float, " -0x3.p-1 ") self.assertRaises(ValueError, float, " +0x3.p-1 ") self.assertEqual(float(" 25.e-1 "), 2.5) - self.assertEqual(support.fcmp(float(" .25e-1 "), .025), 0) + self.assertAlmostEqual(float(" .25e-1 "), .025) def test_floatconversion(self): # Make sure that calls to __float__() work properly |