Let black reformat the code...
This commit is contained in:
parent
cd2085ee71
commit
032db159c9
|
@ -31,8 +31,13 @@ def _cmp_raises_type_error(self, other):
|
|||
"Comparison operators other than == and != not supported by approx objects"
|
||||
)
|
||||
|
||||
|
||||
def _non_numeric_type_error(value):
|
||||
return TypeError("cannot make approximate comparisons to non-numeric values, e.g. {}".format(value))
|
||||
return TypeError(
|
||||
"cannot make approximate comparisons to non-numeric values, e.g. {}".format(
|
||||
value
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# builtin pytest.approx helper
|
||||
|
@ -107,9 +112,7 @@ class ApproxNumpy(ApproxBase):
|
|||
else:
|
||||
return f(x)
|
||||
|
||||
list_scalars = recursive_map(
|
||||
self._approx_scalar,
|
||||
self.expected.tolist())
|
||||
list_scalars = recursive_map(self._approx_scalar, self.expected.tolist())
|
||||
|
||||
return "approx({!r})".format(list_scalars)
|
||||
|
||||
|
@ -171,7 +174,11 @@ class ApproxMapping(ApproxBase):
|
|||
def _check_type(self):
|
||||
for x in self.expected.values():
|
||||
if isinstance(x, type(self.expected)):
|
||||
raise TypeError("pytest.approx() does not support nested dictionaries, e.g. {}".format(self.expected))
|
||||
raise TypeError(
|
||||
"pytest.approx() does not support nested dictionaries, e.g. {}".format(
|
||||
self.expected
|
||||
)
|
||||
)
|
||||
elif not isinstance(x, Number):
|
||||
raise _non_numeric_type_error(self.expected)
|
||||
|
||||
|
@ -201,7 +208,11 @@ class ApproxSequence(ApproxBase):
|
|||
def _check_type(self):
|
||||
for x in self.expected:
|
||||
if isinstance(x, type(self.expected)):
|
||||
raise TypeError("pytest.approx() does not support nested data structures, e.g. {}".format(self.expected))
|
||||
raise TypeError(
|
||||
"pytest.approx() does not support nested data structures, e.g. {}".format(
|
||||
self.expected
|
||||
)
|
||||
)
|
||||
elif not isinstance(x, Number):
|
||||
raise _non_numeric_type_error(self.expected)
|
||||
|
||||
|
@ -325,6 +336,7 @@ class ApproxDecimal(ApproxScalar):
|
|||
"""
|
||||
Perform approximate comparisons where the expected value is a decimal.
|
||||
"""
|
||||
|
||||
DEFAULT_ABSOLUTE_TOLERANCE = Decimal("1e-12")
|
||||
DEFAULT_RELATIVE_TOLERANCE = Decimal("1e-6")
|
||||
|
||||
|
|
|
@ -64,11 +64,14 @@ class TestApprox(object):
|
|||
# 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]])'),
|
||||
(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)
|
||||
|
@ -442,7 +445,7 @@ class TestApprox(object):
|
|||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'x', [None, 'string', ['string'], [[1]], {'key': 'string'}, {'key': {'key': 1}}]
|
||||
"x", [None, "string", ["string"], [[1]], {"key": "string"}, {"key": {"key": 1}}]
|
||||
)
|
||||
def test_expected_value_type_error(self, x):
|
||||
with pytest.raises(TypeError):
|
||||
|
|
Loading…
Reference in New Issue