Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTiedemann committed Mar 13, 2024
1 parent a1d0ee1 commit a7172a9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/codecs/test_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest

from typing import Any, Union

from mlserver.codecs.json import decode_from_bytelike_json_to_dict, encode_to_json_bytes


@pytest.mark.parametrize(
"input, expected",
[
(b"{}", dict()),
("{}", dict()),
('{"hello":"world"}', {"hello": "world"}),
(b'{"hello":"world"}', {"hello": "world"}),
(b'{"hello":"' + "world".encode("utf-8") + b'"}', {"hello": "world"}),
(
b'{"hello":"' + "world".encode("utf-8") + b'", "foo": { "bar": "baz" } }',
{"hello": "world", "foo": {"bar": "baz"}},
),
],
)
def test_decode_input(input: Union[str, bytes], expected):
assert expected == decode_from_bytelike_json_to_dict(input)


@pytest.mark.parametrize(
"expected, input",
[
(b"{}", dict()),
(b'{"hello":"world"}', {"hello": "world"}),
(b'{"hello":"' + "world".encode("utf-8") + b'"}', {"hello": "world"}),
(
b'{"hello":"' + "world".encode("utf-8") + b'","foo":{"bar":"baz"}}',
{"hello": b"world", "foo": {"bar": "baz"}},
),
],
)
def test_encode_input(input: Any, expected: bytes):
assert expected == encode_to_json_bytes(input)

0 comments on commit a7172a9

Please sign in to comment.