-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(targets): Deserialize floats as
decimal.Decimal
(#1809)
* fix(targets): Deserialize floats as `decimal.Decimal` * Address mypy errors * Test unparsable line
- Loading branch information
1 parent
77c3f90
commit 4cbf8a8
Showing
2 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Test IO operations.""" | ||
|
||
from __future__ import annotations | ||
|
||
import decimal | ||
import json | ||
from contextlib import nullcontext | ||
|
||
import pytest | ||
|
||
from singer_sdk.io_base import SingerReader | ||
|
||
|
||
class DummyReader(SingerReader): | ||
def _process_activate_version_message(self, message_dict: dict) -> None: | ||
pass | ||
|
||
def _process_batch_message(self, message_dict: dict) -> None: | ||
pass | ||
|
||
def _process_record_message(self, message_dict: dict) -> None: | ||
pass | ||
|
||
def _process_schema_message(self, message_dict: dict) -> None: | ||
pass | ||
|
||
def _process_state_message(self, message_dict: dict) -> None: | ||
pass | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"line,expected,exception", | ||
[ | ||
pytest.param( | ||
"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, exception): | ||
reader = DummyReader() | ||
with exception: | ||
assert reader.deserialize_json(line) == expected |