Skip to content

Commit

Permalink
Merge pull request pytest-dev#2083 from nicoddemus/approx-check-float
Browse files Browse the repository at this point in the history
Fix error in approx's repr with complex numbers
  • Loading branch information
RonnyPfannschmidt authored Nov 24, 2016
2 parents 38f7562 + 33c0b06 commit b3efd9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
subtle bugs (`#2078`_).
Thanks `@nicoddemus`_ for the PR.

* Fix error message using ``approx`` with complex numbers (`#2082`_).
Thanks `@adler-j`_ for the report and `@nicoddemus`_ for the PR.

*

* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks
`@nedbat`_.
Expand All @@ -15,10 +19,12 @@

*

.. _@adler-j: https://github.com/adler-j
.. _@nedbat: https://github.com/nedbat

.. _#2038: https://github.com/pytest-dev/pytest/issues/2038
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078
.. _#2082: https://github.com/pytest-dev/pytest/issues/2082


3.0.4
Expand Down
3 changes: 3 additions & 0 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,9 @@ def __init__(self, expected, rel=None, abs=None):
self.rel = rel

def __repr__(self):
if isinstance(self.expected, complex):
return str(self.expected)

# Infinities aren't compared using tolerances, so don't show a
# tolerance.
if math.isinf(self.expected):
Expand Down
1 change: 1 addition & 0 deletions testing/python/approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_repr_string(self):
print(approx(inf))
print(approx(1.0, rel=nan))
print(approx(1.0, rel=inf))
print(approx(1.0j, rel=inf))

def test_operator_overloading(self):
assert 1 == approx(1, rel=1e-6, abs=1e-12)
Expand Down

0 comments on commit b3efd9a

Please sign in to comment.