New submission from Chris Barker:

In py3.5, the math.isclose() function was added to the standard library. It can 
be used to compare floating point numbers to see if they are close to each 
other, rather than exactly equal. It's not a lot of code, but there are nuances 
that not every python user should need to understand.

One of the major use cases for isclose() is test code, so it would be good to 
make it easily available in unitest.TestCase.

TestCase.assertAlmostEqual is NOT the same thing, and can only be used properly 
for values near 1.

Enclosed is a patch that adds  assertClose and assertNotClose to unittest, as 
well as tests and additions to the docs.

Still pending: should this support complex numbers, there is a cmath.isclose(). 
If so, but switching on type?

Also -- should this be back-ported to 3.5 as well -- math.isclose() was 
introduced there.

Done in the pyCon sprints.

----------
components: Library (Lib)
files: assertClose.patch
keywords: patch
messages: 267133
nosy: ChrisBarker, ezio.melotti, michael.foord, rbcollins
priority: normal
severity: normal
status: open
title: Adding an assertClose() method to unittest.TestCase
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file43157/assertClose.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27198>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to