[Python-ideas] float comparison in doctes
Nick Coghlan
ncoghlan at gmail.com
Tue Sep 16 01:55:16 CEST 2014
On 16 Sep 2014 06:32, "Steven D'Aprano" <steve at pearwood.info> wrote:
>
> On Mon, Sep 15, 2014 at 12:02:20PM -0700, Kevin Davies wrote:
>
> > It seems that this didn't reach the list directly (see
> > https://mail.python.org/pipermail/python-ideas/2014-August/028956.html),
> > so I'm resending:
>
> >
> > Erik Bray (the author of the +FLOAT_CMP extension in Astropy), Bruce
> > Leban, and I had a short off-thread email discussion. Here are the
> > points:
> >
> > - [Bruce]: ALMOST_EQUAL is the best flag name.
> > - [Erik]: If there's agreement on this, Erik will develop a patch as
soon as he can.
> > - [Erik]: There's no way to adjust the tolerance because there seems
> > to be no easy way to parameterize doctest flags. Ideas are welcome.
>
> With no way to choose between (at minimum) *four* different "almost
> equal" models, and no way to specify a tolerance, I don't think doctest
> ought to have such a directive.
>
> Almost equal can mean:
>
> - round and compare with == (as unittest does)
> - absolute difference
> - relative difference
> - ULP difference
I think it's OK for a doctest flag to just provide the default behaviour
offered by unittest.TestCase.assertAlmostEqual. That aligns well with the
originally intended use case of testing examples in documentation.
If folks want more precise control, they can then switch to full unit
tests. It would be reasonable for the docs for the new flag to point that
out explicitly.
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140916/ad9dc4bc/attachment.html>
More information about the Python-ideas
mailing list