Skip to content

Commit

Permalink
fill out coverage
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <william@trailofbits.com>
  • Loading branch information
woodruffw committed Mar 6, 2024
1 parent a595b32 commit 97d3926
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rfc8785/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

__version__ = "0.0.1"

from ._impl import CanonicalizationError, IntegerDomainError, dump, dumps
from ._impl import CanonicalizationError, FloatDomainError, IntegerDomainError, dump, dumps

__all__ = [
"CanonicalizationError",
"IntegerDomainError",
"FloatDomainError",
"dump",
"dumps",
]
23 changes: 23 additions & 0 deletions test/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,26 @@ def test_es6_float_stringification_full(es6_test_file):

actual = sink.getvalue().decode()
assert actual == expected


def test_integer_domain():
impl.dumps(impl._INT_MAX)
with pytest.raises(impl.IntegerDomainError):
impl.dumps(impl._INT_MAX + 1)

impl.dumps(impl._INT_MIN)
with pytest.raises(impl.IntegerDomainError):
impl.dumps(impl._INT_MIN - 1)


def test_string_invalid_utf8():
# escaped surrogate is fine
impl.dumps("\\udead")
with pytest.raises(impl.CanonicalizationError):
impl.dumps("\udead")


def test_dumps_invalid_type():
with pytest.raises(impl.CanonicalizationError):
# set is not serializable
impl.dumps({1, 2, 3})
8 changes: 8 additions & 0 deletions test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ def test_roundtrip(vector, name):

actual_deserialized = json.loads(actual_output)
assert actual_deserialized == py_input


def test_exception_hierarchy():
assert issubclass(rfc8785.CanonicalizationError, ValueError)
assert issubclass(rfc8785.IntegerDomainError, rfc8785.CanonicalizationError)
assert issubclass(rfc8785.FloatDomainError, rfc8785.CanonicalizationError)
assert not issubclass(rfc8785.IntegerDomainError, rfc8785.FloatDomainError)
assert not issubclass(rfc8785.FloatDomainError, rfc8785.IntegerDomainError)

0 comments on commit 97d3926

Please sign in to comment.