[8.1.x] Fixed Bug Regarding Attribute Error in pytest.approx For Types Implicitly Convertible to Numpy Arrays (#12240)
--------- Co-authored-by: poulami-sau <109125687+poulami-sau@users.noreply.github.com> Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a43b09882d
commit
0675383bac
@@ -763,6 +763,24 @@ class TestApprox:
|
||||
assert a12 != approx(a21)
|
||||
assert a21 != approx(a12)
|
||||
|
||||
def test_numpy_array_implicit_conversion(self) -> None:
|
||||
"""#12114."""
|
||||
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):
|
||||
return np.array(self.vals)
|
||||
|
||||
vec1 = ImplicitArray([1.0, 2.0, 3.0])
|
||||
vec2 = ImplicitArray([1.0, 2.0, 4.0])
|
||||
# see issue #12114 for test case
|
||||
assert vec1 != approx(vec2)
|
||||
|
||||
def test_numpy_array_protocol(self):
|
||||
"""
|
||||
array-like objects such as tensorflow's DeviceArray are handled like ndarray.
|
||||
|
||||
Reference in New Issue
Block a user