[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
99e1fe5f7b
commit
a527cbccd3
|
@ -450,26 +450,25 @@ class ApproxScalar(ApproxBase):
|
|||
# for compatibility with complex numbers.
|
||||
if math.isinf(abs(self.expected)): # type: ignore[arg-type]
|
||||
return False
|
||||
|
||||
tolerance = self.tolerance
|
||||
|
||||
tolerance = self.tolerance
|
||||
expected = self.expected
|
||||
|
||||
if (isinstance(self.expected, Decimal) and not isinstance(actual, Decimal)):
|
||||
|
||||
if isinstance(self.expected, Decimal) and not isinstance(actual, Decimal):
|
||||
try:
|
||||
actual = Decimal(str(actual))
|
||||
tolerance = Decimal(str(tolerance))
|
||||
except TypeError: #
|
||||
except TypeError: #
|
||||
return False
|
||||
elif (isinstance(actual, Decimal) and not isinstance(self.expected, Decimal)):
|
||||
try :
|
||||
elif isinstance(actual, Decimal) and not isinstance(self.expected, Decimal):
|
||||
try:
|
||||
expected = Decimal(str(expected))
|
||||
tolerance = Decimal(str(tolerance))
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
# Return true if the two numbers are within the tolerance.
|
||||
result: bool = (abs(actual - expected) <= tolerance ) # type: ignore[arg-type]
|
||||
result: bool = abs(actual - expected) <= tolerance # type: ignore[arg-type]
|
||||
return result
|
||||
|
||||
# Ignore type because of https://github.com/python/mypy/issues/4266.
|
||||
|
@ -508,11 +507,11 @@ class ApproxScalar(ApproxBase):
|
|||
# we've made sure the user didn't ask for an absolute tolerance only,
|
||||
# because we don't want to raise errors about the relative tolerance if
|
||||
# we aren't even going to use it.
|
||||
|
||||
|
||||
if isinstance(self.rel, Decimal):
|
||||
relative_tolerance = set_default(
|
||||
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
||||
)*Decimal(str(abs(self.expected)))
|
||||
) * Decimal(str(abs(self.expected)))
|
||||
else:
|
||||
relative_tolerance = set_default(
|
||||
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
||||
|
|
|
@ -568,14 +568,14 @@ class TestApprox:
|
|||
expected = [Decimal("1"), Decimal("2")]
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
|
||||
expected = [1, 2]
|
||||
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
|
||||
expected = [Decimal("1"), Decimal("2")]
|
||||
actual = [1.000001, 2.000001]
|
||||
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
def test_list_wrong_len(self):
|
||||
|
@ -618,14 +618,14 @@ class TestApprox:
|
|||
expected = {"b": Decimal("2"), "a": Decimal("1")}
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
|
||||
actual = {"a": 1.000001, "b": 2.000001}
|
||||
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
|
||||
actual = {"a": Decimal("1.000001"), "b": Decimal("2.000001")}
|
||||
expected = {"b": 2, "a": 1}
|
||||
|
||||
|
||||
assert actual == approx(expected)
|
||||
|
||||
def test_dict_wrong_len(self):
|
||||
|
@ -902,4 +902,3 @@ class TestApprox:
|
|||
"""pytest.approx() should raise an error on unordered sequences (#9692)."""
|
||||
with pytest.raises(TypeError, match="only supports ordered sequences"):
|
||||
assert {1, 2, 3} == approx({1, 2, 3})
|
||||
|
Loading…
Reference in New Issue