[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.
|
# for compatibility with complex numbers.
|
||||||
if math.isinf(abs(self.expected)): # type: ignore[arg-type]
|
if math.isinf(abs(self.expected)): # type: ignore[arg-type]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
tolerance = self.tolerance
|
tolerance = self.tolerance
|
||||||
expected = self.expected
|
expected = self.expected
|
||||||
|
|
||||||
if (isinstance(self.expected, Decimal) and not isinstance(actual, Decimal)):
|
if isinstance(self.expected, Decimal) and not isinstance(actual, Decimal):
|
||||||
try:
|
try:
|
||||||
actual = Decimal(str(actual))
|
actual = Decimal(str(actual))
|
||||||
tolerance = Decimal(str(tolerance))
|
tolerance = Decimal(str(tolerance))
|
||||||
except TypeError: #
|
except TypeError: #
|
||||||
return False
|
return False
|
||||||
elif (isinstance(actual, Decimal) and not isinstance(self.expected, Decimal)):
|
elif isinstance(actual, Decimal) and not isinstance(self.expected, Decimal):
|
||||||
try :
|
try:
|
||||||
expected = Decimal(str(expected))
|
expected = Decimal(str(expected))
|
||||||
tolerance = Decimal(str(tolerance))
|
tolerance = Decimal(str(tolerance))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Return true if the two numbers are within the tolerance.
|
# 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
|
return result
|
||||||
|
|
||||||
# Ignore type because of https://github.com/python/mypy/issues/4266.
|
# 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,
|
# 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
|
# because we don't want to raise errors about the relative tolerance if
|
||||||
# we aren't even going to use it.
|
# we aren't even going to use it.
|
||||||
|
|
||||||
if isinstance(self.rel, Decimal):
|
if isinstance(self.rel, Decimal):
|
||||||
relative_tolerance = set_default(
|
relative_tolerance = set_default(
|
||||||
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
||||||
)*Decimal(str(abs(self.expected)))
|
) * Decimal(str(abs(self.expected)))
|
||||||
else:
|
else:
|
||||||
relative_tolerance = set_default(
|
relative_tolerance = set_default(
|
||||||
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
self.rel, self.DEFAULT_RELATIVE_TOLERANCE
|
||||||
|
|
|
@ -568,14 +568,14 @@ class TestApprox:
|
||||||
expected = [Decimal("1"), Decimal("2")]
|
expected = [Decimal("1"), Decimal("2")]
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
expected = [1, 2]
|
expected = [1, 2]
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
expected = [Decimal("1"), Decimal("2")]
|
expected = [Decimal("1"), Decimal("2")]
|
||||||
actual = [1.000001, 2.000001]
|
actual = [1.000001, 2.000001]
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
def test_list_wrong_len(self):
|
def test_list_wrong_len(self):
|
||||||
|
@ -618,14 +618,14 @@ class TestApprox:
|
||||||
expected = {"b": Decimal("2"), "a": Decimal("1")}
|
expected = {"b": Decimal("2"), "a": Decimal("1")}
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
actual = {"a": 1.000001, "b": 2.000001}
|
actual = {"a": 1.000001, "b": 2.000001}
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
actual = {"a": Decimal("1.000001"), "b": Decimal("2.000001")}
|
actual = {"a": Decimal("1.000001"), "b": Decimal("2.000001")}
|
||||||
expected = {"b": 2, "a": 1}
|
expected = {"b": 2, "a": 1}
|
||||||
|
|
||||||
assert actual == approx(expected)
|
assert actual == approx(expected)
|
||||||
|
|
||||||
def test_dict_wrong_len(self):
|
def test_dict_wrong_len(self):
|
||||||
|
@ -902,4 +902,3 @@ class TestApprox:
|
||||||
"""pytest.approx() should raise an error on unordered sequences (#9692)."""
|
"""pytest.approx() should raise an error on unordered sequences (#9692)."""
|
||||||
with pytest.raises(TypeError, match="only supports ordered sequences"):
|
with pytest.raises(TypeError, match="only supports ordered sequences"):
|
||||||
assert {1, 2, 3} == approx({1, 2, 3})
|
assert {1, 2, 3} == approx({1, 2, 3})
|
||||||
|
|
Loading…
Reference in New Issue