From b9faa7fcaf88b5278d8be178f575f0bb37ed2af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Fri, 12 Jul 2024 16:39:46 -0600 Subject: [PATCH] Re-add `SingerReader.deserialize_json` --- singer_sdk/io_base.py | 13 ++++++++++++- tests/core/test_io.py | 8 +++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/singer_sdk/io_base.py b/singer_sdk/io_base.py index f0abc568b..1834b6fad 100644 --- a/singer_sdk/io_base.py +++ b/singer_sdk/io_base.py @@ -51,6 +51,17 @@ def _assert_line_requires(line_dict: dict, requires: set[str]) -> None: msg = f"Line is missing required {', '.join(missing)} key(s): {line_dict}" raise InvalidInputLine(msg) + def deserialize_json(self, line: str) -> dict: # noqa: PLR6301 + """Deserialize a line of json. + + Args: + line: A single line of json. + + Returns: + A dictionary of the deserialized json. + """ + return deserialize_json(line) + def _process_lines(self, file_input: t.IO[str]) -> t.Counter[str]: """Internal method to process jsonl lines from a Singer tap. @@ -62,7 +73,7 @@ def _process_lines(self, file_input: t.IO[str]) -> t.Counter[str]: """ stats: dict[str, int] = defaultdict(int) for line in file_input: - line_dict = deserialize_json(line) + line_dict = self.deserialize_json(line) self._assert_line_requires(line_dict, requires={"type"}) record_type: SingerMessageType = line_dict["type"] diff --git a/tests/core/test_io.py b/tests/core/test_io.py index 9ec9532f2..0fcce614b 100644 --- a/tests/core/test_io.py +++ b/tests/core/test_io.py @@ -10,7 +10,6 @@ import pytest from singer_sdk._singerlib import RecordMessage -from singer_sdk._singerlib.serde import deserialize_json from singer_sdk.io_base import SingerReader, SingerWriter @@ -53,8 +52,9 @@ def _process_state_message(self, message_dict: dict) -> None: ], ) def test_deserialize(line, expected, exception): + reader = DummyReader() with exception: - assert deserialize_json(line) == expected + assert reader.deserialize_json(line) == expected # Benchmark Tests @@ -104,8 +104,10 @@ def test_bench_deserialize_json(benchmark, bench_encoded_record): """Run benchmark for Sink._validator method validate.""" number_of_runs = 1000 + reader = DummyReader() + def run_deserialize_json(): for record in itertools.repeat(bench_encoded_record, number_of_runs): - deserialize_json(record) + reader.deserialize_json(record) benchmark(run_deserialize_json)