diff --git a/_pytest/python_api.py b/_pytest/python_api.py index acc3ea286..ab7a0bc5d 100644 --- a/_pytest/python_api.py +++ b/_pytest/python_api.py @@ -95,7 +95,7 @@ class ApproxNumpyBase(ApproxBase): def __repr__(self): # It might be nice to rewrite this function to account for the # shape of the array... - return repr(list( + return "approx({0!r})".format(list( self._approx_scalar(x) for x in self.expected)) def __eq__(self, actual): @@ -128,7 +128,7 @@ class ApproxMapping(ApproxBase): """ def __repr__(self): - return repr(dict( + return "approx({0!r})".format(dict( (k, self._approx_scalar(v)) for k,v in self.expected.items())) @@ -152,7 +152,7 @@ class ApproxSequence(ApproxBase): seq_type = type(self.expected) if seq_type not in (tuple, list, set): seq_type = list - return repr(seq_type( + return "approx({0!r})".format(seq_type( self._approx_scalar(x) for x in self.expected)) def __eq__(self, actual): diff --git a/testing/python/approx.py b/testing/python/approx.py index 3005a7bbe..a21f644f5 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -28,8 +28,8 @@ class TestApprox(object): if sys.version_info[:2] == (2, 6): tol1, tol2, infr = '???', '???', '???' assert repr(approx(1.0)) == '1.0 {pm} {tol1}'.format(pm=plus_minus, tol1=tol1) - assert repr(approx([1.0, 2.0])) == '[1.0 {pm} {tol1}, 2.0 {pm} {tol2}]'.format(pm=plus_minus, tol1=tol1, tol2=tol2) - assert repr(approx((1.0, 2.0))) == '(1.0 {pm} {tol1}, 2.0 {pm} {tol2})'.format(pm=plus_minus, tol1=tol1, tol2=tol2) + assert repr(approx([1.0, 2.0])) == 'approx([1.0 {pm} {tol1}, 2.0 {pm} {tol2}])'.format(pm=plus_minus, tol1=tol1, tol2=tol2) + assert repr(approx((1.0, 2.0))) == 'approx((1.0 {pm} {tol1}, 2.0 {pm} {tol2}))'.format(pm=plus_minus, tol1=tol1, tol2=tol2) assert repr(approx(inf)) == 'inf' assert repr(approx(1.0, rel=nan)) == '1.0 {pm} ???'.format(pm=plus_minus) assert repr(approx(1.0, rel=inf)) == '1.0 {pm} {infr}'.format(pm=plus_minus, infr=infr) @@ -37,8 +37,8 @@ class TestApprox(object): # Dictionaries aren't ordered, so we need to check both orders. assert repr(approx({'a': 1.0, 'b': 2.0})) in ( - "{{'a': 1.0 {pm} {tol1}, 'b': 2.0 {pm} {tol2}}}".format(pm=plus_minus, tol1=tol1, tol2=tol2), - "{{'b': 2.0 {pm} {tol2}, 'a': 1.0 {pm} {tol1}}}".format(pm=plus_minus, tol1=tol1, tol2=tol2), + "approx({{'a': 1.0 {pm} {tol1}, 'b': 2.0 {pm} {tol2}}})".format(pm=plus_minus, tol1=tol1, tol2=tol2), + "approx({{'b': 2.0 {pm} {tol2}, 'a': 1.0 {pm} {tol1}}})".format(pm=plus_minus, tol1=tol1, tol2=tol2), ) def test_operator_overloading(self):