Skip to content

Commit

Permalink
Fix tests for large ints
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAnotherArchivist committed Jun 16, 2022
1 parent ec07551 commit b33ec84
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions tests/test_ujson.py
Expand Up @@ -564,6 +564,23 @@ def test_decode_numeric_int_exp(test_input):
assert output == json.loads(test_input)


@pytest.mark.parametrize(
"i",
[
-10**25, # very negative
-2**64, # too large in magnitude for a uint64
-2**63 - 1, # too small for a int64
2**64, # too large for a uint64
10**25, # very positive
],
)
def test_encode_decode_big_int(i):
# Test ints that are too large to be represented by a C integer type
for py, j in ((i, str(i)), ([i], f"[{i}]"), ({"i": i}, f'{{"i":{i}}}')):
assert ujson.encode(py) == j
assert ujson.decode(j) == py


@pytest.mark.parametrize(
"test_input, expected",
[
Expand Down Expand Up @@ -600,15 +617,7 @@ def test_decode_range_raises(test_input, expected):
("[,31337]", ujson.JSONDecodeError), # array leading comma fail
("[,]", ujson.JSONDecodeError), # array only comma fail
("[]]", ujson.JSONDecodeError), # array unmatched bracket fail
("18446744073709551616", ujson.JSONDecodeError), # too big value
("-90223372036854775809", ujson.JSONDecodeError), # too small value
("-23058430092136939529", ujson.JSONDecodeError), # too small value
("-11529215046068469760", ujson.JSONDecodeError), # too small value
("18446744073709551616", ujson.JSONDecodeError), # very too big value
("23058430092136939529", ujson.JSONDecodeError), # too big value
("-90223372036854775809", ujson.JSONDecodeError), # very too small value
("{}\n\t a", ujson.JSONDecodeError), # with trailing non whitespaces
("[18446744073709551616]", ujson.JSONDecodeError), # array with big int
('{"age", 44}', ujson.JSONDecodeError), # read bad object syntax
],
)
Expand Down Expand Up @@ -682,11 +691,6 @@ def test_dumps_raises(test_input, expected_exception, expected_message):
(float("nan"), OverflowError),
(float("inf"), OverflowError),
(-float("inf"), OverflowError),
(12839128391289382193812939, OverflowError),
([12839128391289382193812939], OverflowError),
([12839128391289382193812939, 42], OverflowError),
({"a": 12839128391289382193812939}, OverflowError),
({"a": 12839128391289382193812939, "b": 42}, OverflowError),
],
)
def test_encode_raises_allow_nan(test_input, expected_exception):
Expand Down

0 comments on commit b33ec84

Please sign in to comment.