Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jul 1, 2024
1 parent 2405ac0 commit b74e534
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/jiter-python/tests/test_jiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ def test_lossless_floats():
assert str(f) == '123.456789123456789e45'
assert repr(f) == 'LosslessFloat(123.456789123456789e45)'

f = jiter.from_json(b'123', float_mode='lossless-float')
assert isinstance(f, int)
assert f == 123

with pytest.raises(ValueError, match='expected value at line 1 column 1'):
jiter.from_json(b'wrong', float_mode='lossless-float')

with pytest.raises(ValueError, match='trailing characters at line 1 column 2'):
jiter.from_json(b'1wrong', float_mode='lossless-float')



def test_decimal_floats():
f = jiter.from_json(b'12.3')
Expand All @@ -272,11 +283,15 @@ def test_decimal_floats():
assert isinstance(f, Decimal)
assert f == Decimal('1.23456789123456789E+47')

f = jiter.from_json(b'123', float_mode='decimal')
assert isinstance(f, int)
assert f == 123

with pytest.raises(ValueError, match='expected value at line 1 column 1'):
jiter.from_json(b'wrong', float_mode='decimal')

def test_lossless_floats_int():
v = jiter.from_json(b'123', float_mode='lossless-float')
assert isinstance(v, int)
assert v == 123
with pytest.raises(ValueError, match='trailing characters at line 1 column 2'):
jiter.from_json(b'1wrong', float_mode='decimal')


def test_unicode_roundtrip():
Expand Down

0 comments on commit b74e534

Please sign in to comment.