Add a convenient and correct way to compare floats.

This commit is contained in:
Kale Kundert
2016-03-06 18:53:48 -08:00
parent c2b9196a7c
commit 6f5e1e386a
2 changed files with 128 additions and 1 deletions

27
testing/python/approx.py Normal file
View File

@@ -0,0 +1,27 @@
import pytest
import doctest
class MyDocTestRunner(doctest.DocTestRunner):
def __init__(self):
doctest.DocTestRunner.__init__(self)
def report_failure(self, out, test, example, got):
raise AssertionError("'{}' evaluates to '{}', not '{}'".format(
example.source.strip(), got.strip(), example.want.strip()))
class TestApprox:
def test_approx(self):
parser = doctest.DocTestParser()
test = parser.get_doctest(
pytest.approx.__doc__,
{'approx': pytest.approx},
pytest.approx.__name__,
None, None,
)
runner = MyDocTestRunner()
runner.run(test)