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

1from __future__ import print_function 

2from builtins import str 

3import os 

4import unittest 

5import shutil 

6import unittest 

7import yaml 

8from fundamentals.utKit import utKit 

9from fundamentals import tools 

10from os.path import expanduser 

11home = expanduser("~") 

12 

13packageDirectory = utKit("").get_project_root() 

14settingsFile = packageDirectory + "/test_settings.yaml" 

15# settingsFile = home + "/.config/soxspipe.recipes/soxspipe.recipes.yaml" 

16su = tools( 

17 arguments={"settingsFile": settingsFile}, 

18 docString=__doc__, 

19 logLevel="DEBUG", 

20 options_first=False, 

21 projectName=None, 

22 defaultSettingsFile=False 

23) 

24arguments, settings, log, dbConn = su.setup() 

25 

26# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE 

27moduleDirectory = os.path.dirname(__file__) 

28utKit = utKit(moduleDirectory) 

29log, dbConn, pathToInputDir, pathToOutputDir = utKit.setupModule() 

30utKit.tearDownModule() 

31 

32try: 

33 shutil.rmtree(pathToOutputDir) 

34except: 

35 pass 

36# COPY INPUT TO OUTPUT DIR 

37shutil.copytree(pathToInputDir, pathToOutputDir) 

38 

39# Recursively create missing directories 

40if not os.path.exists(pathToOutputDir): 

41 os.makedirs(pathToOutputDir) 

42 

43# xt-setup-unit-testing-files-and-folders 

44 

45class test_yaml_to_database(unittest.TestCase): 

46 

47 def test_single_yaml_to_database_function(self): 

48 # COPY INPUT TO OUTPUT DIR 

49 import shutil 

50 try: 

51 shutil.rmtree(pathToOutputDir) 

52 except: 

53 pass 

54 # COPY INPUT TO OUTPUT DIR 

55 shutil.copytree(pathToInputDir, pathToOutputDir) 

56 

57 from fundamentals.mysql import yaml_to_database 

58 yaml2db = yaml_to_database( 

59 log=log, 

60 settings=settings, 

61 dbConn=dbConn, 

62 pathToInputDir=pathToOutputDir + "yaml" 

63 ) 

64 yaml2db.add_yaml_file_content_to_database( 

65 filepath=pathToOutputDir + "yaml/20161219105124.yaml" 

66 ) 

67 

68 def test_yaml_to_database_function(self): 

69 

70 from fundamentals.mysql import yaml_to_database 

71 yaml2db = yaml_to_database( 

72 log=log, 

73 settings=settings, 

74 dbConn=dbConn, 

75 pathToInputDir=pathToOutputDir + "/yaml" 

76 ) 

77 yaml2db.ingest() 

78 

79 def test_yaml_to_database_function_exception(self): 

80 

81 from fundamentals.mysql import yaml_to_database 

82 try: 

83 this = yaml_to_database( 

84 log=log, 

85 settings=settings, 

86 dbConn=dbConn, 

87 fakeKey="break the code" 

88 ) 

89 this.get() 

90 assert False 

91 except Exception as e: 

92 assert True 

93 # print(str(e)) 

94 

95 # x-print-testpage-for-pessto-marshall-web-object 

96 

97 # x-class-to-test-named-worker-function