-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from dyvenia/dev
Release 0.4.4 PR
- Loading branch information
Showing
54 changed files
with
2,350 additions
and
45 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
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
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,34 @@ | ||
from viadot.flows import ADLSGen1ToAzureSQL | ||
from unittest import mock | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_init( | ||
TEST_CSV_FILE_BLOB_PATH, TEST_PARQUET_FILE_PATH | ||
): | ||
instance = ADLSGen1ToAzureSQL( | ||
name="test_adls_gen1_azure_sql_flow", | ||
path=TEST_PARQUET_FILE_PATH, | ||
blob_path=TEST_CSV_FILE_BLOB_PATH, | ||
schema="sandbox", | ||
table="test_bcp", | ||
dtypes={"country": "VARCHAR(25)", "sales": "INT"}, | ||
if_exists="replace", | ||
) | ||
assert instance | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_mock( | ||
TEST_CSV_FILE_BLOB_PATH, TEST_PARQUET_FILE_PATH | ||
): | ||
with mock.patch.object(ADLSGen1ToAzureSQL, "run", return_value=True) as mock_method: | ||
instance = ADLSGen1ToAzureSQL( | ||
name="test_adls_gen1_azure_sql_flow", | ||
path=TEST_PARQUET_FILE_PATH, | ||
blob_path=TEST_CSV_FILE_BLOB_PATH, | ||
schema="sandbox", | ||
table="test_bcp", | ||
dtypes={"country": "VARCHAR(25)", "sales": "INT"}, | ||
if_exists="replace", | ||
) | ||
instance.run() | ||
mock_method.assert_called_with() |
69 changes: 69 additions & 0 deletions
69
tests/integration/flows/test_adls_gen1_to_azure_sql_new.py
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,69 @@ | ||
import os | ||
import pytest | ||
import pandas as pd | ||
from unittest import mock | ||
from viadot.flows import ADLSGen1ToAzureSQLNew | ||
|
||
|
||
d = {"country": [1, 2], "sales": [3, 4]} | ||
df = pd.DataFrame(data=d) | ||
SCHEMA = "sandbox" | ||
TABLE = "test_bcp" | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_init_args(): | ||
|
||
flow = ADLSGen1ToAzureSQLNew( | ||
name="test_adls_gen1_gen2_flow", | ||
gen1_path="test_file_1.csv", | ||
gen2_path="test_file_2.csv", | ||
schema=SCHEMA, | ||
table=TABLE, | ||
dtypes={"country": "INT", "sales": "INT"}, | ||
if_exists="replace", | ||
) | ||
|
||
assert flow | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_mock(): | ||
with mock.patch.object( | ||
ADLSGen1ToAzureSQLNew, "run", return_value=True | ||
) as mock_method: | ||
instance = ADLSGen1ToAzureSQLNew( | ||
name="test_adls_gen1_gen2_flow", | ||
gen1_path="folder1/example_file.csv", | ||
gen2_path="folder2/example_file.csv", | ||
schema="sandbox", | ||
table="test_bcp", | ||
dtypes={"country": "VARCHAR(25)", "sales": "INT"}, | ||
if_exists="replace", | ||
) | ||
instance.run() | ||
mock_method.assert_called_with() | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_flow_run_mock(): | ||
|
||
d = {"country": [1, 2], "sales": [3, 4]} | ||
df = pd.DataFrame(data=d) | ||
|
||
with mock.patch( | ||
"viadot.flows.adls_gen1_to_azure_sql_new.gen1_to_df_task.bind" | ||
) as gen1_to_df_task_mock_bind_method_mock: | ||
gen1_to_df_task_mock_bind_method_mock.return_value = df | ||
|
||
flow = ADLSGen1ToAzureSQLNew( | ||
name="test_adls_g1g2", | ||
gen1_path="example_path", | ||
gen2_path="raw/test/test.csv", | ||
dtypes={"country": "VARCHAR(25)", "sales": "INT"}, | ||
if_exists="replace", | ||
table="test", | ||
schema="sandbox", | ||
) | ||
|
||
result = flow.run() | ||
|
||
assert result.is_successful() | ||
os.remove("test_adls_g1g2.csv") |
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,25 @@ | ||
from viadot.flows import ADLSGen1ToGen2 | ||
from unittest import mock | ||
|
||
|
||
def test_adls_gen1_gen2_init(TEST_PARQUET_FILE_PATH_2): | ||
|
||
flow = ADLSGen1ToGen2( | ||
"test_adls_gen1_gen2_init", | ||
gen1_path=TEST_PARQUET_FILE_PATH_2, | ||
gen2_path=TEST_PARQUET_FILE_PATH_2, | ||
) | ||
assert flow | ||
|
||
|
||
def test_adls_gen1_to_azure_sql_new_mock( | ||
TEST_PARQUET_FILE_PATH, TEST_PARQUET_FILE_PATH_2 | ||
): | ||
with mock.patch.object(ADLSGen1ToGen2, "run", return_value=True) as mock_method: | ||
instance = ADLSGen1ToGen2( | ||
"test_adls_gen1_gen2_init", | ||
gen1_path=TEST_PARQUET_FILE_PATH, | ||
gen2_path=TEST_PARQUET_FILE_PATH_2, | ||
) | ||
instance.run() | ||
mock_method.assert_called_with() |
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,40 @@ | ||
from viadot.flows import DuckDBTransform | ||
import pytest | ||
import pandas as pd | ||
from unittest import mock | ||
from viadot.sources import DuckDB | ||
import os | ||
|
||
TABLE = "test_table" | ||
SCHEMA = "test_schema" | ||
TABLE_MULTIPLE_PARQUETS = "test_multiple_parquets" | ||
DATABASE_PATH = "test_db_123.duckdb" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def duckdb(): | ||
duckdb = DuckDB(credentials=dict(database=DATABASE_PATH)) | ||
yield duckdb | ||
os.remove(DATABASE_PATH) | ||
|
||
|
||
def test_create_table_from_parquet(duckdb, TEST_PARQUET_FILE_PATH): | ||
duckdb.create_table_from_parquet( | ||
schema=SCHEMA, table=TABLE, path=TEST_PARQUET_FILE_PATH | ||
) | ||
|
||
|
||
def test_duckdb_transform_init(): | ||
instance = DuckDBTransform("test_duckdb_transform", query="select * from test") | ||
|
||
assert instance | ||
|
||
|
||
def test_duckdb_transform_flow_run(): | ||
instance = DuckDBTransform( | ||
"test_duckdb_transform", | ||
query=f"select * from {SCHEMA}.{TABLE}", | ||
credentials=dict(database=DATABASE_PATH), | ||
) | ||
result = instance.run() | ||
assert result.is_successful() |
Oops, something went wrong.