Skip to content

Commit

Permalink
Use caplog fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jan 3, 2023
1 parent 02291f6 commit 31a4d73
Showing 1 changed file with 61 additions and 67 deletions.
128 changes: 61 additions & 67 deletions tests/core/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Test _typing - specifically conform_record_data_types()."""

import datetime
import logging
import unittest

import pytest

from singer_sdk.helpers._typing import (
ConformanceLevel,
Expand Down Expand Up @@ -156,72 +158,64 @@ def test_nested_objects_are_conformed():
assert actual_output == expected_output


class TestSimpleEval(unittest.TestCase):
def test_simple_schema_removes_types(self):
schema = PropertiesList(
Property("keep", StringType),
).to_dict()

record = {"keep": "hello", "remove": "goodbye"}

expected_output = {"keep": "hello"}

with self.assertLogs("log", level="WARN") as logs:
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
self.assertEqual(
logs.output,
[
"WARNING:log:Properties ('remove',) were present in the 'test_stream' stream but not found in catalog "
"schema. Ignoring."
],
)

def test_nested_objects_remove_types(self):
schema = PropertiesList(
Property("object", PropertiesList(Property("keep", StringType))),
).to_dict()

record = {"object": {"keep": "hello", "remove": "goodbye"}}

expected_output = {"object": {"keep": "hello"}}

with self.assertLogs("log", level="WARN") as logs:
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
self.assertEqual(
logs.output,
[
"WARNING:log:Properties ('object.remove',) were present in the 'test_stream' stream but not found in "
"catalog schema. Ignoring."
],
)

def test_object_arrays_remove_types(self):
schema = PropertiesList(
Property("list", ArrayType(PropertiesList(Property("keep", StringType)))),
).to_dict()

record = {"list": [{"keep": "hello", "remove": "goodbye"}]}

expected_output = {"list": [{"keep": "hello"}]}

with self.assertLogs("log", level="WARN") as logs:
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
self.assertEqual(
logs.output,
[
"WARNING:log:Properties ('list.remove',) were present in the 'test_stream' stream but not found in "
"catalog schema. Ignoring."
],
)
def test_simple_schema_removes_types(caplog: pytest.LogCaptureFixture):
schema = PropertiesList(
Property("keep", StringType),
).to_dict()

record = {"keep": "hello", "remove": "goodbye"}

expected_output = {"keep": "hello"}

with caplog.at_level(logging.WARNING):
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
assert caplog.records[0].message == (
"Properties ('remove',) were present in the 'test_stream' stream but not "
"found in catalog schema. Ignoring."
)


def test_nested_objects_remove_types(caplog: pytest.LogCaptureFixture):
schema = PropertiesList(
Property("object", PropertiesList(Property("keep", StringType))),
).to_dict()

record = {"object": {"keep": "hello", "remove": "goodbye"}}

expected_output = {"object": {"keep": "hello"}}

with caplog.at_level(logging.WARNING):
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
assert caplog.records[0].message == (
"Properties ('object.remove',) were present in the 'test_stream' stream "
"but not found in catalog schema. Ignoring."
)


def test_object_arrays_remove_types(caplog: pytest.LogCaptureFixture):
schema = PropertiesList(
Property("list", ArrayType(PropertiesList(Property("keep", StringType)))),
).to_dict()

record = {"list": [{"keep": "hello", "remove": "goodbye"}]}

expected_output = {"list": [{"keep": "hello"}]}

with caplog.at_level(logging.WARNING):
actual_output = conform_record_data_types(
"test_stream", record, schema, ConformanceLevel.RECURSIVE, logger
)
assert actual_output == expected_output
assert caplog.records[0].message == (
"Properties ('list.remove',) were present in the 'test_stream' stream but "
"not found in catalog schema. Ignoring."
)


def test_conform_primitives():
Expand Down

0 comments on commit 31a4d73

Please sign in to comment.