Skip to content

Commit

Permalink
added test case in testing/python/approx.py based on test case provid…
Browse files Browse the repository at this point in the history
…ed by reporter in issue pytest-dev#12114
  • Loading branch information
poulami-sau committed Apr 22, 2024
1 parent c077526 commit 485e8ef
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions testing/python/approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,23 @@ def test_numpy_array_wrong_shape(self):
assert a12 != approx(a21)
assert a21 != approx(a12)

def test_numpy_array_implicit_conversion(self):
np = pytest.importorskip("numpy")

class ImplicitArray:
"""Type which is implicitly convertible to a numpy array."""

def __init__(self, vals):
self.vals = vals

def __array__(self, dtype=None, copy=None):
print("called __array__ in ImplicitArray")
return np.array(self.vals)

vec1 = ImplicitArray([1.0, 2.0, 3.0])
vec2 = ImplicitArray([1.0, 2.0, 4.0])
assert vec1 != approx(vec2)

def test_numpy_array_protocol(self):
"""
array-like objects such as tensorflow's DeviceArray are handled like ndarray.
Expand Down

0 comments on commit 485e8ef

Please sign in to comment.