@@ -24,37 +24,18 @@ def report_failure(self, out, test, example, got):
2424
2525
2626class TestApprox :
27- @pytest .fixture
28- def plus_minus (self ):
29- return "\u00b1 "
30-
31- def test_repr_string (self , plus_minus ):
32- tol1 , tol2 , infr = "1.0e-06" , "2.0e-06" , "inf"
33- assert repr (approx (1.0 )) == "1.0 {pm} {tol1}" .format (pm = plus_minus , tol1 = tol1 )
34- assert repr (
35- approx ([1.0 , 2.0 ])
36- ) == "approx([1.0 {pm} {tol1}, 2.0 {pm} {tol2}])" .format (
37- pm = plus_minus , tol1 = tol1 , tol2 = tol2
38- )
39- assert repr (
40- approx ((1.0 , 2.0 ))
41- ) == "approx((1.0 {pm} {tol1}, 2.0 {pm} {tol2}))" .format (
42- pm = plus_minus , tol1 = tol1 , tol2 = tol2
43- )
27+ def test_repr_string (self ):
28+ assert repr (approx (1.0 )) == "1.0 ± 1.0e-06"
29+ assert repr (approx ([1.0 , 2.0 ])) == "approx([1.0 ± 1.0e-06, 2.0 ± 2.0e-06])"
30+ assert repr (approx ((1.0 , 2.0 ))) == "approx((1.0 ± 1.0e-06, 2.0 ± 2.0e-06))"
4431 assert repr (approx (inf )) == "inf"
45- assert repr (approx (1.0 , rel = nan )) == "1.0 {pm} ???" .format (pm = plus_minus )
46- assert repr (approx (1.0 , rel = inf )) == "1.0 {pm} {infr}" .format (
47- pm = plus_minus , infr = infr
48- )
32+ assert repr (approx (1.0 , rel = nan )) == "1.0 ± ???"
33+ assert repr (approx (1.0 , rel = inf )) == "1.0 ± inf"
4934
5035 # Dictionaries aren't ordered, so we need to check both orders.
5136 assert repr (approx ({"a" : 1.0 , "b" : 2.0 })) in (
52- "approx({{'a': 1.0 {pm} {tol1}, 'b': 2.0 {pm} {tol2}}})" .format (
53- pm = plus_minus , tol1 = tol1 , tol2 = tol2
54- ),
55- "approx({{'b': 2.0 {pm} {tol2}, 'a': 1.0 {pm} {tol1}}})" .format (
56- pm = plus_minus , tol1 = tol1 , tol2 = tol2
57- ),
37+ "approx({'a': 1.0 ± 1.0e-06, 'b': 2.0 ± 2.0e-06})" ,
38+ "approx({'b': 2.0 ± 2.0e-06, 'a': 1.0 ± 1.0e-06})" ,
5839 )
5940
6041 def test_repr_complex_numbers (self ):
@@ -73,20 +54,20 @@ def test_repr_complex_numbers(self):
7354 assert repr (approx (3.3 + 4.4 * 1j , abs = 0.02 )) == "(3.3+4.4j) ± 2.0e-02 ∠ ±180°"
7455
7556 @pytest .mark .parametrize (
76- "value, repr_string " ,
57+ "value, expected_repr_string " ,
7758 [
78- (5.0 , "approx(5.0 {pm} 5.0e-06)" ),
79- ([5.0 ], "approx([5.0 {pm} 5.0e-06])" ),
80- ([[5.0 ]], "approx([[5.0 {pm} 5.0e-06]])" ),
81- ([[5.0 , 6.0 ]], "approx([[5.0 {pm} 5.0e-06, 6.0 {pm} 6.0e-06]])" ),
82- ([[5.0 ], [6.0 ]], "approx([[5.0 {pm} 5.0e-06], [6.0 {pm} 6.0e-06]])" ),
59+ (5.0 , "approx(5.0 ± 5.0e-06)" ),
60+ ([5.0 ], "approx([5.0 ± 5.0e-06])" ),
61+ ([[5.0 ]], "approx([[5.0 ± 5.0e-06]])" ),
62+ ([[5.0 , 6.0 ]], "approx([[5.0 ± 5.0e-06, 6.0 ± 6.0e-06]])" ),
63+ ([[5.0 ], [6.0 ]], "approx([[5.0 ± 5.0e-06], [6.0 ± 6.0e-06]])" ),
8364 ],
8465 )
85- def test_repr_nd_array (self , plus_minus , value , repr_string ):
66+ def test_repr_nd_array (self , value , expected_repr_string ):
8667 """Make sure that arrays of all different dimensions are repr'd correctly."""
8768 np = pytest .importorskip ("numpy" )
8869 np_array = np .array (value )
89- assert repr (approx (np_array )) == repr_string . format ( pm = plus_minus )
70+ assert repr (approx (np_array )) == expected_repr_string
9071
9172 def test_operator_overloading (self ):
9273 assert 1 == approx (1 , rel = 1e-6 , abs = 1e-12 )
0 commit comments