"""Tests for the mapping classes.""" import pytest from snowflake_etl.util import schema_map def test_sql_type(): """Test mapping the real type to FLOAT.""" sql_type = schema_map.SQLType('real') assert sql_type.sql() == 'REAL' assert sql_type.sql_snowflake('mysql') == 'FLOAT' with pytest.raises(KeyError): schema_map.SQLType('unreal').sql_snowflake('mysql') def test_sql_type_num(): """Test mapping the numeric type to NUMBER.""" sql_type = schema_map.SQLNumType('decimal', 10, 6) assert sql_type.sql_snowflake('mysql') == 'NUMBER(38,10)' def test_sql_type_char(): """Test mapping the character type to VARCHAR.""" sql_type = schema_map.SQLCharType('MEDIUMTEXT', 100) assert sql_type.sql_snowflake('mysql') == 'VARCHAR(100)' def test_sql_column_not_null(): """Test creating not nullable SQL column definition. (If nullable parameter passed). """ col = schema_map.SQLColumn( name='test', type=schema_map.SQLType('real'), nullable=False) assert col.sql_snowflake('mysql') == 'TEST FLOAT NOT NULL' def test_sql_column_nullable(): """Test creating nullable SQL column definition. (If nullable parameter not passed. """ col = schema_map.SQLColumn( name='test', type=schema_map.SQLNumType('INTEGER', 1, 0)) assert col.sql_snowflake('mysql') == 'TEST NUMBER(12,0)'