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 

5from enum import Enum 

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

7from sdc_etl_libs.sdc_data_schema.schema_toolbox import SchemaToolbox 

8 

9 

10def test_generate_file_output_args_happy_path(mocker): 

11 """ 

12 That that file output args func works as expected 

13 """ 

14 

15 data_schema = { 

16 "fields": [ 

17 {"name": "COL1", "type": {"type": "string"}}, 

18 {"name": "COL2", "type": {"type": "string"}, "add_column": True}, 

19 {"name": "COL3", "type": {"type": "string"}}, 

20 ] 

21 } 

22 

23 endpoint_schema = { 

24 "type": "source", 

25 "tag": "main_source", 

26 "info": { 

27 "type": "sftp", 

28 "file_info": { 

29 "type": "csv", 

30 "opts": { 

31 "file_regex": ".*ECS", 

32 "delimiter": "|", 

33 "headers": False, 

34 "encoding": "utf-8", 

35 "file_name": None, 

36 "compression_type": None, 

37 "format": None, 

38 "line_terminator": None 

39 } 

40 } 

41 } 

42 } 

43 

44 #TODO: Really want to be able to mock out the Enums that generate_file_output_args uses... 

45 

46 #class PandasCSVMapperMock(Enum): 

47 # delimiter = "delimiterx" 

48 # headers = "header" 

49 # compression_type = "compression" 

50 # line_terminator = "lineterminator" 

51 # encoding = "encoding" 

52 

53 #class FileEnumMapperMock(Enum): 

54 # csv = { 

55 # "source": PandasCSVMapperMock 

56 # } 

57 

58 #mocker.patch('sdc_etl_libs.sdc_data_schema.schema_enums.FileEnumMapper', return_value=FileEnumMapperMock, 

59 # autospec=True) 

60 #mocker.patch('sdc_etl_libs.sdc_data_schema.schema_enums.PandasCSVMapper', return_value=PandasCSVMapperMock, 

61 # autospec=True) 

62 

63 result = SchemaToolbox.generate_file_output_args(data_schema, endpoint_schema) 

64 assert result == {'delimiter': '|', 'header': False, 'encoding': 'utf-8', 'compression': None, 'lineterminator': None, 'names': ['COL1', 'COL3']} 

65 

66