Files
pytest2/testing/python/approx.py
Kale Kundert bf97d5b817 Use the plus/minus unicode symbol in the repr string.
This was a challenge because it had to work in python2 and python3,
which have almost opposite unicode models, and I couldn't use the six
library.  I'm also not sure the solution I found would work in python3
before python3.3, because I use the u'' string prefix which I think was
initially not part of python3.
2016-03-07 16:40:41 -08:00

34 lines
908 B
Python

# encoding: utf-8
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_doctests(self):
parser = doctest.DocTestParser()
test = parser.get_doctest(
pytest.approx.__doc__,
{'approx': pytest.approx},
pytest.approx.__name__,
None, None,
)
runner = MyDocTestRunner()
runner.run(test)
def test_repr_string(self):
# Just make sure the Unicode handling doesn't raise any exceptions.
print(pytest.approx(1.0))
print(pytest.approx([1.0, 2.0, 3.0]))