[Python-Dev] fcmp() in test.support

Raymond Hettinger raymond.hettinger at gmail.com
Fri Jan 28 19:51:19 CET 2011


On Jan 28, 2011, at 10:09 AM, Brett Cannon wrote:

> On Thu, Jan 27, 2011 at 20:55, Eli Bendersky <eliben at gmail.com> wrote:
>> I'm working on improving the .rst documentation of test.support (Issue
>> 11015), and came upon the undocumented "fcmp" function that's being
>> exported from test.support, along with a "FUZZ"constant.
>> 
>> As I search through the tests (py3k trunk), I see fcmp() is being used
>> only in two places in a fairly trivial way:
>> 1. test_float: where it can be directly replaced by assertAlmostEqual
>> from unittest
>> 2. test_builtin: where the assertion can also be easily rewritten in
>> terms of assertAlmostEqual
>> 
>> Although fcmp seems to provide extra functionality over
>> assertAlmostEqual, the above makes me think it should probably be
>> removed altogether, or added to unittest if it's still deemed
>> important.
>> 
>> +/- ?
> 
> I say drop it if it can be done so safely.

Yes, please remove fcmp() altogether.
Like you said, the usage is trivial.

If you're feeling bold, replace them with assertEqual(),
the tests look like they produce exact values even
in floating point.


Raymond


------------------------------


~/py32 $ ack "fcmp" --python
Doc/tools/pygments/lexers/asm.py
261:             r'|lshr|ashr|and|or|xor|icmp|fcmp'

Lib/test/support.py
36:    "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "SAVEDCWD", "temp_cwd",
354:def fcmp(x, y): # fuzzy comparison function
364:            outcome = fcmp(x[i], y[i])

Lib/test/test_builtin.py
13:from test.support import fcmp, TESTFN, unlink,  run_unittest, check_warnings
397:        self.assertTrue(not fcmp(divmod(3.25, 1.0), (3.0, 0.25)))
398:        self.assertTrue(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)))
399:        self.assertTrue(not fcmp(divmod(3.25, -1.0), (-4.0, -0.75)))
400:        self.assertTrue(not fcmp(divmod(-3.25, -1.0), (3.0, -0.25)))

Lib/test/test_float.py
91:        self.assertEqual(support.fcmp(float("  .25e-1  "), .025), 0)



More information about the Python-Dev mailing list