fix(test): correct _coerce_number inf/nan test assertions

The test 'test_inf_stays_string_for_integer_only' incorrectly asserted
that _coerce_number('inf') returns float('inf'), but the function
correctly returns the original string 'inf' because infinity is not
JSON-serializable.

Fixed the assertion to expect the string 'inf', and added two new tests
for negative infinity and NaN edge cases to improve coverage of the
non-JSON-serializable number guard in _coerce_number().
This commit is contained in:
vominh1919 2026-04-26 19:50:04 +07:00 committed by Teknium
parent edf9c75621
commit 652f8e6f3e

View file

@ -64,10 +64,23 @@ class TestCoerceNumber:
def test_scientific_notation(self):
assert _coerce_number("1e5") == 100000
def test_inf_stays_string_for_integer_only(self):
"""Infinity should not be converted to int."""
def test_inf_stays_string(self):
"""Infinity is not JSON-serializable, so it should stay as string."""
result = _coerce_number("inf")
assert result == "inf"
assert isinstance(result, str)
def test_negative_inf_stays_string(self):
"""Negative infinity should also stay as string."""
result = _coerce_number("-inf")
assert result == "-inf"
assert isinstance(result, str)
def test_nan_stays_string(self):
"""NaN is not JSON-serializable, so it should stay as string."""
result = _coerce_number("nan")
assert result == "nan"
assert isinstance(result, str)
def test_negative_float(self):
assert _coerce_number("-2.5") == -2.5