From 6e32a1f73d91c6040960a6e84841cdcffb0393e5 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 1 Aug 2018 07:04:25 -0300 Subject: [PATCH] Use parametrize in repr test for nd arrays --- testing/python/approx.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/testing/python/approx.py b/testing/python/approx.py index 8c77b4945..c31b8bc5a 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -59,22 +59,21 @@ class TestApprox(object): ), ) - def test_repr_nd_array(self, plus_minus): - # Make sure that arrays of all different dimensions are repr'd - # correctly. + @pytest.mark.parametrize( + "value, repr_string", + [ + (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") - examples = [ - (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) + np_array = np.array(value) + assert repr(approx(np_array)) == repr_string.format(pm=plus_minus) def test_operator_overloading(self): assert 1 == approx(1, rel=1e-6, abs=1e-12)