Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Refactor utility functions verify_data and verify_schema to AssertionHelper class #254

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ smoke-test
.meltano/**
.tox/**
.secrets/**
.idea
.vscode/**
output/**
.env
Expand Down
12 changes: 7 additions & 5 deletions target_postgres/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ def copy_table_structure(

@contextmanager
def _connect(self) -> t.Iterator[sqlalchemy.engine.Connection]:
with self._engine.connect().execution_options() as conn:
engine = self._engine
with engine.connect().execution_options() as conn:
yield conn
engine.dispose()

def drop_table(
self, table: sqlalchemy.Table, connection: sqlalchemy.engine.Connection
Expand Down Expand Up @@ -330,7 +332,7 @@ def create_empty_table( # type: ignore[override]
"""Create an empty target table.

Args:
full_table_name: the target table name.
table_name: the target table name.
schema: the JSON schema for the new table.
primary_keys: list of key properties.
partition_keys: list of partition keys.
Expand Down Expand Up @@ -425,7 +427,7 @@ def _create_empty_column( # type: ignore[override]
"""Create a new column.

Args:
full_table_name: The target table name.
table_name: The target table name.
column_name: The name of the new column.
sql_type: SQLAlchemy type engine to be used in creating the new column.

Expand Down Expand Up @@ -489,7 +491,7 @@ def _adapt_column_type( # type: ignore[override]
"""Adapt table column type to support the new JSON schema type.

Args:
full_table_name: The target table name.
table_name: The target table name.
column_name: The target column name.
sql_type: The new SQLAlchemy type.

Expand Down Expand Up @@ -720,7 +722,7 @@ def _get_column_type( # type: ignore[override]
"""Get the SQL type of the declared column.

Args:
full_table_name: The name of the table.
table_name: The name of the table.
column_name: The name of the column.

Returns:
Expand Down
5 changes: 5 additions & 0 deletions target_postgres/tests/data_files/array_boolean.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"type": "SCHEMA", "stream": "array_boolean", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "value": {"type": "array", "items": {"type": "boolean"}}}}}
{"type": "RECORD", "stream": "array_boolean", "record": {"id": 1, "value": [ true, false ]}}
{"type": "RECORD", "stream": "array_boolean", "record": {"id": 2, "value": [ false ]}}
{"type": "RECORD", "stream": "array_boolean", "record": {"id": 3, "value": [ false, true, true, false ]}}
{"type": "STATE", "value": {"array_boolean": 3}}
6 changes: 0 additions & 6 deletions target_postgres/tests/data_files/array_data.singer

This file was deleted.

5 changes: 5 additions & 0 deletions target_postgres/tests/data_files/array_number.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"type": "SCHEMA", "stream": "array_number", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "value": {"type": "array", "items": {"type": "number"}}}}}
{"type": "RECORD", "stream": "array_number", "record": {"id": 1, "value": [ 42.42, 84.84, 23 ]}}
{"type": "RECORD", "stream": "array_number", "record": {"id": 2, "value": [ 1.0 ]}}
{"type": "RECORD", "stream": "array_number", "record": {"id": 3, "value": [ 1.11, 2.22, 3, 4, 5.55 ]}}
{"type": "STATE", "value": {"array_number": 3}}
6 changes: 6 additions & 0 deletions target_postgres/tests/data_files/array_string.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"type": "SCHEMA", "stream": "array_string", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "value": {"type": "array","items": {"type": "string"}}}}}
{"type": "RECORD", "stream": "array_string", "record": {"id": 1, "value": [ "apple", "orange", "pear" ]}}
{"type": "RECORD", "stream": "array_string", "record": {"id": 2, "value": [ "banana", "apple" ]}}
{"type": "RECORD", "stream": "array_string", "record": {"id": 3, "value": [ "pear" ]}}
{"type": "RECORD", "stream": "array_string", "record": {"id": 4, "value": [ "orange", "banana", "apple", "pear" ]}}
{"type": "STATE", "value": {"array_string": 4}}
5 changes: 5 additions & 0 deletions target_postgres/tests/data_files/array_timestamp.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"type": "SCHEMA", "stream": "array_timestamp", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "value": {"type": "array", "items": {"type": "string", "format": "date-time"}}}}}
{"type": "RECORD", "stream": "array_timestamp", "record": {"id": 1, "value": [ "2023-12-13T01:15:02", "2023-12-13T01:16:02" ]}}
{"type": "RECORD", "stream": "array_timestamp", "record": {"id": 2, "value": [ "2023-12-13T01:15:02" ]}}
{"type": "RECORD", "stream": "array_timestamp", "record": {"id": 3, "value": [ "2023-12-13T01:15:02", "2023-12-13T01:16:02", "2023-12-13T01:17:02" ]}}
{"type": "STATE", "value": {"array_timestamp": 3}}
3 changes: 3 additions & 0 deletions target_postgres/tests/data_files/object_mixed.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"type": "SCHEMA", "stream": "object_mixed", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "value": {"type": "object"}}}}
{"type": "RECORD", "stream": "object_mixed", "record": {"id": 1, "value": {"string": "foo", "integer": 42, "float": 42.42, "timestamp": "2023-12-13T01:15:02", "array_boolean": [true, false], "array_float": [42.42, 84.84], "array_integer": [42, 84], "array_string": ["foo", "bar"], "nested_object": {"foo": "bar"}}}}
{"type": "STATE", "value": {"object_mixed": 1}}
4 changes: 3 additions & 1 deletion target_postgres/tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class BasePostgresSDKTests:
@pytest.fixture()
def connection(self, runner):
engine = create_engine(runner)
return engine.connect()
with engine.connect() as connection:
yield connection
engine.dispose()


SDKTests = get_target_test_class(
Expand Down
Loading
Loading