Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import sys 

2import os 

3sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../../") 

4from sdc_etl_libs.database_helpers.SnowflakeDatabase import SnowflakeDatabase 

5from sdc_etl_libs.sdc_exchange_endpoints.database_endpoints.SDCColumnCleanseStylesEnums import \ 

6 StyleEnums 

7import pytest 

8 

9 

10def test_clean_column_names(): 

11 

12 # All characters to uppercase 

13 assert SnowflakeDatabase.clean_column_name("total_sales", StyleEnums['SNOWFLAKE']) == "TOTAL_SALES" 

14 # Spaces to underscore 

15 assert SnowflakeDatabase.clean_column_name("TOTAL SALES", StyleEnums['SNOWFLAKE']) == "TOTAL_SALES" 

16 # Trailing space trimmed 

17 assert SnowflakeDatabase.clean_column_name("TOTAL_SALES ", StyleEnums['SNOWFLAKE']) == "TOTAL_SALES" 

18 # Multiple underscores to single undercore 

19 assert SnowflakeDatabase.clean_column_name("TOTAL____SALES__EOM ", StyleEnums['SNOWFLAKE']) == "TOTAL_SALES_EOM" 

20 # Octothorp to NUM 

21 assert SnowflakeDatabase.clean_column_name("# Of Stores", StyleEnums['SNOWFLAKE']) == "NUM_OF_STORES" 

22 # Non-alphanumeric to underscore 

23 assert SnowflakeDatabase.clean_column_name("Employee: Last Name, First Name", StyleEnums['SNOWFLAKE']) == "EMPLOYEE_LAST_NAME_FIRST_NAME" 

24 

25 # Extremely messy column names 

26 assert SnowflakeDatabase.clean_column_name("Recruiting Workflow Profile (Person Full Name: First, Last Label)", StyleEnums['SNOWFLAKE']) \ 

27 == "RECRUITING_WORKFLOW_PROFILE_PERSON_FULL_NAME_FIRST_LAST_LABEL" 

28 assert SnowflakeDatabase.clean_column_name("_____1 # Email -: Payment Failed________ ", StyleEnums['SNOWFLAKE']) \ 

29 == "_1_NUM_EMAIL_PAYMENT_FAILED"