[Python-ideas] float comparison in doctest

Nick Coghlan ncoghlan at gmail.com
Tue Aug 12 09:35:04 CEST 2014


On 12 Aug 2014 04:16, "Terry Reedy" <tjreedy at udel.edu> wrote:
>
> On 8/11/2014 12:25 PM, Kevin Davies wrote:
>>
>> Erik Bray has created a nifty addition to doctest to compare floating
>> point numbers using a `+FLOAT_CMP` flag.
>
>
> The problem with a simple flag is that almost_equal should sometimes be
absolute and sometimes relative and in both cases a parameter in needed. I
think there have been vague proposals for a float method, but
> "a - b < delta" is shorter than "a.almost_equat(b, abs=delta)" and
probably easier to understand.

For more formal tests, we already have unittest.TestCase.assertAlmostEqual.

This sounds like a reasonable flag for doctest's original purpose of
checking that examples in docs are showing sensible answers.

Cheers,
Nick.

>
>
> > It is implemented within
>>
>> Astropy (http://www.astropy.org/) and the related issue is
>> https://github.com/astropy/astropy/issues/2662.
>
>
> The related issue is applying flags to a block of test with a Sphinx
directive.
>
>
>> According to Erik, it
>> may need some tweaks, but I think it would be a really useful feature to
>> make available in the doctest package itself.
>
>
> Erik would have to offer his code.
>
> --
> Terry Jan Reedy
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140812/7719a4d9/attachment.html>


More information about the Python-ideas mailing list