Skip to content

Commit

Permalink
Update tests to expect NaN/Infinity support and overflow handling
Browse files Browse the repository at this point in the history
🤖 Generated with Claude CLI.
Co-Authored-By: Claude <[email protected]>
  • Loading branch information
catherio committed Jan 11, 2025
1 parent 7a1a5dc commit d6606f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
6 changes: 3 additions & 3 deletions test/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_numpy_array_f16_edge(self):
),
option=orjson.OPT_SERIALIZE_NUMPY,
)
== b"[null,null,null,-0.0,0.0,3.140625]"
== b"[Infinity,-Infinity,NaN,-0.0,0.0,3.140625]"
)

def test_numpy_array_f32_edge(self):
Expand All @@ -184,7 +184,7 @@ def test_numpy_array_f32_edge(self):
),
option=orjson.OPT_SERIALIZE_NUMPY,
)
== b"[null,null,null,-0.0,0.0,3.1415927]"
== b"[Infinity,-Infinity,NaN,-0.0,0.0,3.1415927]"
)

def test_numpy_array_f64_edge(self):
Expand All @@ -203,7 +203,7 @@ def test_numpy_array_f64_edge(self):
),
option=orjson.OPT_SERIALIZE_NUMPY,
)
== b"[null,null,null,-0.0,0.0,3.141592653589793]"
== b"[Infinity,-Infinity,NaN,-0.0,0.0,3.141592653589793]"
)

def test_numpy_array_d1_f64(self):
Expand Down
20 changes: 10 additions & 10 deletions test/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def test_n_number_negative_NaN(self):
"""
n_number_-NaN.json
"""
self._run_fail_json("n_number_-NaN.json")
self._run_pass_json("n_number_-NaN.json")

def test_n_number_negative_1(self):
"""
Expand Down Expand Up @@ -942,13 +942,13 @@ def test_n_number_negative_Inf(self):
"""
n_number_Inf.json
"""
self._run_fail_json("n_number_Inf.json")
self._run_pass_json("n_number_Inf.json")

def test_n_number_NaN(self):
"""
n_number_NaN.json
"""
self._run_fail_json("n_number_NaN.json")
self._run_pass_json("n_number_NaN.json")

def test_n_number_U_FF11_fullwidth_digit_one(self):
"""
Expand Down Expand Up @@ -978,7 +978,7 @@ def test_n_number_infinity(self):
"""
n_number_infinity.json
"""
self._run_fail_json("n_number_infinity.json")
self._run_pass_json("n_number_infinity.json")

def test_n_number_invalid_(self):
"""
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def test_n_number_minus_infinity(self):
"""
n_number_minus_infinity.json
"""
self._run_fail_json("n_number_minus_infinity.json")
self._run_pass_json("n_number_minus_infinity.json")

def test_n_number_minus_sign_with_trailing_garbage(self):
"""
Expand Down Expand Up @@ -1742,31 +1742,31 @@ def test_i_number_huge_exp(self):
"""
i_number_huge_exp.json
"""
self._run_fail_json("i_number_huge_exp.json")
self._run_pass_json("i_number_huge_exp.json")

def test_i_number_neg_int_huge_exp(self):
"""
i_number_neg_int_huge_exp.json
"""
self._run_fail_json("i_number_neg_int_huge_exp.json")
self._run_pass_json("i_number_neg_int_huge_exp.json")

def test_i_number_pos_double_huge_exp(self):
"""
i_number_pos_double_huge_exp.json
"""
self._run_fail_json("i_number_pos_double_huge_exp.json")
self._run_pass_json("i_number_pos_double_huge_exp.json")

def test_i_number_real_neg_overflow(self):
"""
i_number_real_neg_overflow.json
"""
self._run_fail_json("i_number_real_neg_overflow.json")
self._run_pass_json("i_number_real_neg_overflow.json")

def test_i_number_real_pos_overflow(self):
"""
i_number_real_pos_overflow.json
"""
self._run_fail_json("i_number_real_pos_overflow.json")
self._run_pass_json("i_number_real_pos_overflow.json")

def test_i_number_real_underflow(self):
"""
Expand Down
31 changes: 13 additions & 18 deletions test/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,37 +346,32 @@ def test_null_array(self):

def test_nan_dumps(self):
"""
NaN serializes to null
NaN serializes to NaN
"""
assert orjson.dumps(float("NaN")) == b"null"
assert orjson.dumps(float("NaN")) == b"NaN"

def test_nan_loads(self):
"""
NaN is not valid JSON
NaN is valid JSON in this fork
"""
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[NaN]")
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[nan]")
assert str(orjson.loads("[NaN]")[0]) == "nan"
assert str(orjson.loads("[nan]")[0]) == "nan"

def test_infinity_dumps(self):
"""
Infinity serializes to null
Infinity serializes to Infinity
"""
assert orjson.dumps(float("Infinity")) == b"null"
assert orjson.dumps(float("Infinity")) == b"Infinity"
assert orjson.dumps(float("-Infinity")) == b"-Infinity"

def test_infinity_loads(self):
"""
Infinity, -Infinity is not valid JSON
Infinity, -Infinity is valid JSON in this fork
"""
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[infinity]")
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[Infinity]")
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[-Infinity]")
with pytest.raises(orjson.JSONDecodeError):
orjson.loads("[-infinity]")
assert str(orjson.loads("[Infinity]")[0]) == "inf"
assert str(orjson.loads("[infinity]")[0]) == "inf"
assert str(orjson.loads("[-Infinity]")[0]) == "-inf"
assert str(orjson.loads("[-infinity]")[0]) == "-inf"

def test_int_53(self):
"""
Expand Down

0 comments on commit d6606f3

Please sign in to comment.