Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steinitzu committed Sep 23, 2023
1 parent e0f7097 commit a66a950
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
29 changes: 17 additions & 12 deletions tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
{
"name": "col5_precision",
"data_type": "text",
"precision": 21,
"precision": 25,
"nullable": False
},
{
Expand Down Expand Up @@ -290,17 +290,22 @@ def assert_all_data_types_row(
3
)

# binary column
if "col7" in db_mapping:
if isinstance(db_mapping["col7"], str):
try:
db_mapping["col7"] = bytes.fromhex(db_mapping["col7"]) # redshift returns binary as hex string
except ValueError:
if not allow_base64_binary:
raise
db_mapping["col7"] = base64.b64decode(db_mapping["col7"], validate=True)
else:
db_mapping["col7"] = bytes(db_mapping["col7"])
# redshift and bigquery return strings from structured fields
for binary_col in ["col7", "col7_precision"]:
if binary_col in db_mapping:
if isinstance(db_mapping[binary_col], str):
try:
db_mapping[binary_col] = bytes.fromhex(
db_mapping[binary_col]
) # redshift returns binary as hex string
except ValueError:
if not allow_base64_binary:
raise
db_mapping[binary_col] = base64.b64decode(
db_mapping[binary_col], validate=True
)
else:
db_mapping[binary_col] = bytes(db_mapping[binary_col])

# redshift and bigquery return strings from structured fields
if "col9" in db_mapping:
Expand Down
4 changes: 2 additions & 2 deletions tests/load/bigquery/test_bigquery_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_create_table(gcp_client: BigQueryClient) -> None:
assert "`col11` TIME" in sql
assert "`col1_precision` INTEGER NOT NULL" in sql
assert "`col4_precision` TIMESTAMP NOT NULL" in sql
assert "`col5_precision` STRING(21) " in sql
assert "`col5_precision` STRING(25) " in sql
assert "`col6_precision` NUMERIC(6,2) NOT NULL" in sql
assert "`col7_precision` BYTES(19)" in sql
assert "`col11_precision` TIME NOT NULL" in sql
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_alter_table(gcp_client: BigQueryClient) -> None:
assert "ADD COLUMN `col11` TIME" in sql
assert "ADD COLUMN `col1_precision` INTEGER NOT NULL" in sql
assert "ADD COLUMN `col4_precision` TIMESTAMP NOT NULL" in sql
assert "ADD COLUMN `col5_precision` STRING(21)" in sql
assert "ADD COLUMN `col5_precision` STRING(25)" in sql
assert "ADD COLUMN `col6_precision` NUMERIC(6,2) NOT NULL" in sql
assert "ADD COLUMN `col7_precision` BYTES(19)" in sql
assert "ADD COLUMN `col11_precision` TIME NOT NULL" in sql
Expand Down
4 changes: 2 additions & 2 deletions tests/load/mssql/test_mssql_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_create_table(client: MsSqlClient) -> None:
assert '"col11" time NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" datetimeoffset(3) NOT NULL' in sql
assert '"col5_precision" nvarchar(21)' in sql
assert '"col5_precision" nvarchar(25)' in sql
assert '"col6_precision" decimal(6,2) NOT NULL' in sql
assert '"col7_precision" varbinary(19)' in sql
assert '"col11_precision" time(3) NOT NULL' in sql
Expand All @@ -65,7 +65,7 @@ def test_alter_table(client: MsSqlClient) -> None:
assert '"col11" time NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" datetimeoffset(3) NOT NULL' in sql
assert '"col5_precision" nvarchar(21)' in sql
assert '"col5_precision" nvarchar(25)' in sql
assert '"col6_precision" decimal(6,2) NOT NULL' in sql
assert '"col7_precision" varbinary(19)' in sql
assert '"col11_precision" time(3) NOT NULL' in sql
4 changes: 2 additions & 2 deletions tests/load/postgres/test_postgres_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_create_table(client: PostgresClient) -> None:
assert '"col11" time without time zone NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" timestamp (3) with time zone NOT NULL' in sql
assert '"col5_precision" varchar(21)' in sql
assert '"col5_precision" varchar(25)' in sql
assert '"col6_precision" numeric(6,2) NOT NULL' in sql
assert '"col7_precision" bytea' in sql
assert '"col11_precision" time (3) without time zone NOT NULL' in sql
Expand All @@ -66,7 +66,7 @@ def test_alter_table(client: PostgresClient) -> None:
assert '"col11" time without time zone NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" timestamp (3) with time zone NOT NULL' in sql
assert '"col5_precision" varchar(21)' in sql
assert '"col5_precision" varchar(25)' in sql
assert '"col6_precision" numeric(6,2) NOT NULL' in sql
assert '"col7_precision" bytea' in sql
assert '"col11_precision" time (3) without time zone NOT NULL' in sql
Expand Down
4 changes: 2 additions & 2 deletions tests/load/redshift/test_redshift_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_create_table(client: RedshiftClient) -> None:
assert '"col11" time without time zone NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" timestamp with time zone NOT NULL' in sql
assert '"col5_precision" varchar(21)' in sql
assert '"col5_precision" varchar(25)' in sql
assert '"col6_precision" numeric(6,2) NOT NULL' in sql
assert '"col7_precision" varbinary(19)' in sql
assert '"col11_precision" time without time zone NOT NULL' in sql
Expand All @@ -82,7 +82,7 @@ def test_alter_table(client: RedshiftClient) -> None:
assert '"col11" time without time zone NOT NULL' in sql
assert '"col1_precision" smallint NOT NULL' in sql
assert '"col4_precision" timestamp with time zone NOT NULL' in sql
assert '"col5_precision" varchar(21)' in sql
assert '"col5_precision" varchar(25)' in sql
assert '"col6_precision" numeric(6,2) NOT NULL' in sql
assert '"col7_precision" varbinary(19)' in sql
assert '"col11_precision" time without time zone NOT NULL' in sql
Expand Down

0 comments on commit a66a950

Please sign in to comment.