From acc7320db451c4f93b63caded69403f8cf66d58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Rami=CC=81rez=20Mondrago=CC=81n?= Date: Wed, 5 Jul 2023 11:09:41 -0600 Subject: [PATCH] Test unparsable line --- tests/core/test_io.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/core/test_io.py b/tests/core/test_io.py index e32ea4191..c8de02447 100644 --- a/tests/core/test_io.py +++ b/tests/core/test_io.py @@ -3,6 +3,8 @@ from __future__ import annotations import decimal +import json +from contextlib import nullcontext import pytest @@ -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