[Python-ideas] PEP 485: A Function for testing approximate equality
rosuav at gmail.com
Fri Jan 23 18:45:35 CET 2015
On Sat, Jan 24, 2015 at 4:21 AM, Chris Barker <chris.barker at noaa.gov> wrote:
>> If you wanted to make that check more widely available, why not simply
>> make it into a full-fledged function rather than an assertion?
> That would be an option, but I don't think the one in unittest is the right
> test anyway -- its focus on on number of decimal digits after the decimal
> place is not generally useful. (that would make some sense for the Decimal
>> And if
>> it's not suitable for that purpose, why does this PEP not propose
>> updating the unittest assertion to use the new function?
> well, for backward compatibility reasons, I had just assumed it was off the
> table -- or a long, painful road anyway. And the unitest is very vested in
> it's OO structure -- would we want add free-form functions to it?
Updating the assertion to use the new function would be a matter of
tweaking the implementation of unittest's assertAlmostEqual() to now
call this function and assert that it returns True. The OO structure
of unittest wouldn't be affected; just the exact definition of one
particular assertion. I'd say that's a point worth mentioning in the
PEP. Conceptually, this is going to do the same thing; yes, it's a
change of definition, but obviously this won't be done in a point
release anyway. It would make reasonable sense to sync them up.
Alternatively, if you choose not to have that as part of the proposal,
it would be worth adding a word or two of docs to unittest stating
that assertAlmostEqual is not the same as is_close_to (and/or add
"assertCloseTo" which would use it), as the existing implementation is
all about absolute difference.
More information about the Python-ideas