Skip to content

Commit

Permalink
fix: Do not emit log message if no record properties were ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 11, 2022
1 parent ff3d65e commit dc8cef9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
16 changes: 0 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion singer_sdk/helpers/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,6 @@ def conform_record_data_types( # noqa: C901
rec[property_name] = boolean_representation
else:
rec[property_name] = elem
_warn_unmapped_properties(stream_name, tuple(unmapped_properties), logger)
if unmapped_properties:
_warn_unmapped_properties(stream_name, tuple(unmapped_properties), logger)
return rec
45 changes: 38 additions & 7 deletions tests/core/test_record_typing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Typing tests."""

from __future__ import annotations

import logging
from datetime import datetime
from typing import Any, Dict
from typing import Any

import pendulum
import pytest
Expand All @@ -15,31 +17,60 @@


@pytest.mark.parametrize(
"record,schema,expected_row",
"record,schema,expected_row,ignore_props_message",
[
(
{"updatedAt": pendulum.parse("2021-08-25T20:05:28+00:00")},
{"properties": {"updatedAt": True}},
{"updatedAt": "2021-08-25T20:05:28+00:00"},
None,
),
(
{"updatedAt": pendulum.parse("2021-08-25T20:05:28Z")},
{"properties": {"updatedAt": True}},
{"updatedAt": "2021-08-25T20:05:28+00:00"},
None,
),
(
{"updatedAt": pendulum.parse("2021-08-25T20:05:28")},
{"properties": {"updatedAt": True}},
{"updatedAt": "2021-08-25T20:05:28+00:00"},
None,
),
(
{"present": 1, "absent": "2"},
{"properties": {"present": {"type": "integer"}}},
{"present": 1},
(
"Properties ('absent',) were present in the 'test-stream' stream but "
"not found in catalog schema. Ignoring."
),
),
],
ids=[
"datetime with offset",
"datetime with timezone",
"datetime without timezone",
"ignored_props_message",
],
)
def test_conform_record_data_types(record: Dict[str, Any], schema: dict, expected_row):
def test_conform_record_data_types(
record: dict[str, Any],
schema: dict,
expected_row: dict,
ignore_props_message: str,
caplog: pytest.LogCaptureFixture,
):
stream_name = "test-stream"
# TODO: mock this out
logger = logging.getLogger()
actual = conform_record_data_types(stream_name, record, schema, logger)
print(record["updatedAt"].isoformat())
logger = logging.getLogger("test-logger")

with caplog.at_level(logging.INFO, logger=logger.name):
actual = conform_record_data_types(stream_name, record, schema, logger)
if ignore_props_message:
assert ignore_props_message in caplog.text
else:
assert not caplog.text

assert actual == expected_row


Expand Down

0 comments on commit dc8cef9

Please sign in to comment.