Add "approx" to all the repr-strings.

This commit is contained in:
Kale Kundert 2017-07-03 22:44:37 -07:00
parent 9597e674d9
commit 8524a57075
No known key found for this signature in database
GPG Key ID: C6238221D17CAFAE
2 changed files with 7 additions and 7 deletions

View File

@ -95,7 +95,7 @@ class ApproxNumpyBase(ApproxBase):
def __repr__(self): def __repr__(self):
# It might be nice to rewrite this function to account for the # It might be nice to rewrite this function to account for the
# shape of the array... # shape of the array...
return repr(list( return "approx({0!r})".format(list(
self._approx_scalar(x) for x in self.expected)) self._approx_scalar(x) for x in self.expected))
def __eq__(self, actual): def __eq__(self, actual):
@ -128,7 +128,7 @@ class ApproxMapping(ApproxBase):
""" """
def __repr__(self): def __repr__(self):
return repr(dict( return "approx({0!r})".format(dict(
(k, self._approx_scalar(v)) (k, self._approx_scalar(v))
for k,v in self.expected.items())) for k,v in self.expected.items()))
@ -152,7 +152,7 @@ class ApproxSequence(ApproxBase):
seq_type = type(self.expected) seq_type = type(self.expected)
if seq_type not in (tuple, list, set): if seq_type not in (tuple, list, set):
seq_type = list seq_type = list
return repr(seq_type( return "approx({0!r})".format(seq_type(
self._approx_scalar(x) for x in self.expected)) self._approx_scalar(x) for x in self.expected))
def __eq__(self, actual): def __eq__(self, actual):

View File

@ -28,8 +28,8 @@ class TestApprox(object):
if sys.version_info[:2] == (2, 6): if sys.version_info[:2] == (2, 6):
tol1, tol2, infr = '???', '???', '???' tol1, tol2, infr = '???', '???', '???'
assert repr(approx(1.0)) == '1.0 {pm} {tol1}'.format(pm=plus_minus, tol1=tol1) 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])) == 'approx([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(inf)) == 'inf' 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=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) 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. # Dictionaries aren't ordered, so we need to check both orders.
assert repr(approx({'a': 1.0, 'b': 2.0})) in ( 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), "approx({{'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({{'b': 2.0 {pm} {tol2}, 'a': 1.0 {pm} {tol1}}})".format(pm=plus_minus, tol1=tol1, tol2=tol2),
) )
def test_operator_overloading(self): def test_operator_overloading(self):