Use parametrize in repr test for nd arrays
This commit is contained in:
parent
611d254ed5
commit
6e32a1f73d
|
@ -59,21 +59,20 @@ class TestApprox(object):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_repr_nd_array(self, plus_minus):
|
@pytest.mark.parametrize(
|
||||||
# Make sure that arrays of all different dimensions are repr'd
|
"value, repr_string",
|
||||||
# correctly.
|
[
|
||||||
|
(5., "approx(5.0 {pm} 5.0e-06)"),
|
||||||
|
([5.], "approx([5.0 {pm} 5.0e-06])"),
|
||||||
|
([[5.]], "approx([[5.0 {pm} 5.0e-06]])"),
|
||||||
|
([[5., 6.]], "approx([[5.0 {pm} 5.0e-06, 6.0 {pm} 6.0e-06]])"),
|
||||||
|
([[5.], [6.]], "approx([[5.0 {pm} 5.0e-06], [6.0 {pm} 6.0e-06]])"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_repr_nd_array(self, plus_minus, value, repr_string):
|
||||||
|
"""Make sure that arrays of all different dimensions are repr'd correctly."""
|
||||||
np = pytest.importorskip("numpy")
|
np = pytest.importorskip("numpy")
|
||||||
examples = [
|
np_array = np.array(value)
|
||||||
(np.array(5.), "approx(5.0 {pm} 5.0e-06)"),
|
|
||||||
(np.array([5.]), "approx([5.0 {pm} 5.0e-06])"),
|
|
||||||
(np.array([[5.]]), "approx([[5.0 {pm} 5.0e-06]])"),
|
|
||||||
(np.array([[5., 6.]]), "approx([[5.0 {pm} 5.0e-06, 6.0 {pm} 6.0e-06]])"),
|
|
||||||
(
|
|
||||||
np.array([[5.], [6.]]),
|
|
||||||
"approx([[5.0 {pm} 5.0e-06], [6.0 {pm} 6.0e-06]])",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
for np_array, repr_string in examples:
|
|
||||||
assert repr(approx(np_array)) == repr_string.format(pm=plus_minus)
|
assert repr(approx(np_array)) == repr_string.format(pm=plus_minus)
|
||||||
|
|
||||||
def test_operator_overloading(self):
|
def test_operator_overloading(self):
|
||||||
|
|
Loading…
Reference in New Issue