"""Tests for gen.py.""" from pathlib import Path import pandas as pd import pytest from feed_ingestion.flows.youtube_monthly import gen THIS_DIR = Path(__file__).parent @pytest.mark.parametrize( 'column_name, expected', [ ('col1', 'col1'), ('Col 1', 'col_1'), ('Col : Header', 'col_header'), ] ) def test_column_name_to_sql(column_name, expected): """Test column_name_to_sql.""" converted = gen.sqlize_column_name(column_name) assert converted == expected def test_df_to_ddl(): """Test df_to_ddl.""" data_dict = { 'col1': [1, 0, 0], 'col : Str': ['s1', 's2', 's3'], 'Something Revenue': [0, 0, 0], } df = pd.DataFrame.from_dict(data_dict) expected = """ CREATE TABLE staging_raw_youtube_monthly_ ( col1 INTEGER, col_str TEXT, something_revenue REAL ) """.strip() ddl_create = gen.df_to_ddl(df) assert ddl_create == expected @pytest.mark.parametrize( 'csv_filename', [ 'music_summary.csv', 'YouTube_dmgi_M_20230101_ADJ_claim_summary_v1-1.csv', 'YouTube_theorchardmusic_M_20230101_ADJ_claim_summary_v1-1.csv', ] ) def test_csv_to_ddl(csv_filename): """Test csv_to_ddl.""" csv_file = THIS_DIR / 'files' / csv_filename ddl_file = THIS_DIR / 'files' / f'{csv_filename}.ddl.sql' result = gen.csv_to_ddl(str(csv_file)) assert result == ddl_file.read_text()