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

1 

2import os 

3import sys 

4import pytest 

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

6from sdc_etl_libs.sdc_dataframe.SDCDataframeEnums import SDCDFTypes 

7from sdc_etl_libs.sdc_data_schema.schema_toolbox import SchemaToolbox 

8 

9 

10def test_determine_dataframe_from_schema_happy_path(): 

11 

12 data_schema = { 

13 "estimated_row_size": "1b", 

14 "estimated_row_count": 10 

15 } 

16 

17 result = SchemaToolbox.determine_dataframe_type_from_schema(data_schema) 

18 assert result == SDCDFTypes.PANDAS 

19 

20 

21def test_determine_dataframe_from_schema_missing_params(): 

22 """ 

23 Ensure exception is raised if keys needed to determine dataframe are missing 

24 """ 

25 

26 data_schema = { 

27 "estimated_row_size": "1b" 

28 } 

29 

30 with pytest.raises(Exception) as excep_info: 

31 SchemaToolbox.determine_dataframe_type_from_schema(data_schema) 

32 assert '"estimated_row_count" is missing in data schema and is required' in str(excep_info.value) 

33 

34 

35def test_determine_dataframe_from_schema_bad_data_types(): 

36 """ 

37 Ensure exception is raised if keys needed to determine dataframe are the wrong type 

38 """ 

39 

40 data_schema = { 

41 "estimated_row_size": "1b", 

42 "estimated_row_count": "x" 

43 } 

44 

45 with pytest.raises(Exception) as excep_info: 

46 SchemaToolbox.determine_dataframe_type_from_schema(data_schema) 

47 assert '"estimated_row_count" in data schema is not of type int' in str(excep_info.value) 

48 

49 data_schema = { 

50 "estimated_row_size": 1, 

51 "estimated_row_count": 10 

52 } 

53 

54 with pytest.raises(Exception) as excep_info: 

55 SchemaToolbox.determine_dataframe_type_from_schema(data_schema) 

56 assert '"estimated_row_size" in data schema is not of type str' in str(excep_info.value)