drop the duplicate approx call

update test to include both np.array(actual) and np.array(expected)
This commit is contained in:
abrammer 2018-07-24 21:18:44 -04:00
parent 514ca6f4ad
commit f0db64ac2e
2 changed files with 11 additions and 5 deletions

View File

@ -211,10 +211,9 @@ class ApproxScalar(ApproxBase):
the pre-specified tolerance.
"""
if _is_numpy_array(actual):
return (
ApproxNumpy(actual, rel=self.rel, abs=self.abs, nan_ok=self.nan_ok)
== self.expected
)
import numpy as np
return np.all(abs(self.expected - actual) <= self.tolerance)
# Short-circuit exact equality.
if actual == self.expected:

View File

@ -346,15 +346,22 @@ class TestApprox(object):
"""
quick check that numpy rel/abs args are handled correctly
for comparison against an np.array
- 3.6.4 would approx both actual / expected if np.array
regardless of which value was passed to approx()
Means tolerance could be calculated against bad test return
"""
np = pytest.importorskip("numpy")
expected = 100
actual = 99
assert actual != pytest.approx(expected, abs=0.1, rel=0)
assert np.array(actual) != pytest.approx(expected, abs=0.1, rel=0)
assert actual != pytest.approx(np.array(expected), abs=0.1, rel=0)
assert np.array(actual) != pytest.approx(np.array(expected), abs=0.1, rel=0)
assert actual == pytest.approx(expected, abs=0, rel=0.01)
assert np.array(actual) == pytest.approx(expected, abs=0, rel=0.1)
assert np.array(actual) == pytest.approx(expected, abs=0, rel=0.01)
assert actual == pytest.approx(np.array(expected), abs=0, rel=0.01)
assert np.array(actual) == pytest.approx(np.array(expected), abs=0, rel=0.01)
def test_numpy_array_wrong_shape(self):
np = pytest.importorskip("numpy")