Skip to content

Commit

Permalink
Test unparsable line
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 5, 2023
1 parent 5c64316 commit acc7320
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/core/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from __future__ import annotations

import decimal
import json
from contextlib import nullcontext

import pytest

Expand All @@ -27,19 +29,27 @@ def _process_state_message(self, message_dict: dict) -> None:


@pytest.mark.parametrize(
"line,expected",
"line,expected,exception",
[
pytest.param(
b'{"type": "RECORD", "stream": "users", "record": {"id": 1, "value": 1.23}}', # noqa: E501
"not-valid-json",
None,
pytest.raises(json.decoder.JSONDecodeError),
id="unparsable",
),
pytest.param(
'{"type": "RECORD", "stream": "users", "record": {"id": 1, "value": 1.23}}', # noqa: E501
{
"type": "RECORD",
"stream": "users",
"record": {"id": 1, "value": decimal.Decimal("1.23")},
},
nullcontext(),
id="record",
),
],
)
def test_deserialize(line, expected):
def test_deserialize(line, expected, exception):
reader = DummyReader()
assert reader.deserialize_json(line) == expected
with exception:
assert reader.deserialize_json(line) == expected

0 comments on commit acc7320

Please sign in to comment.