Add support for pytest.approx comparisons between scalar and array (inverted order)

This commit is contained in:
Tadeu Manoel
2018-03-14 16:29:04 -03:00
parent c34dde7a3f
commit 161d4e5fe4
2 changed files with 21 additions and 5 deletions

View File

@@ -402,3 +402,14 @@ class TestApprox(object):
assert actual != approx(expected, rel=5e-8, abs=0)
assert approx(expected, rel=5e-7, abs=0) == actual
assert approx(expected, rel=5e-8, abs=0) != actual
def test_numpy_scalar_with_array(self):
np = pytest.importorskip('numpy')
actual = 1.0
expected = np.array([1 + 1e-7, 1 - 1e-8])
assert actual == approx(expected, rel=5e-7, abs=0)
assert actual != approx(expected, rel=5e-8, abs=0)
assert approx(expected, rel=5e-7, abs=0) == actual
assert approx(expected, rel=5e-8, abs=0) != actual