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 yaml 

7from atelParser.utKit import utKit 

8from fundamentals import tools 

9from os.path import expanduser 

10home = expanduser("~") 

11 

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

13settingsFile = packageDirectory + "/test_settings.yaml" 

14 

15su = tools( 

16 arguments={"settingsFile": settingsFile}, 

17 docString=__doc__, 

18 logLevel="DEBUG", 

19 options_first=False, 

20 projectName=None, 

21 defaultSettingsFile=False 

22) 

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

24 

25# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

26moduleDirectory = os.path.dirname(__file__) 

27pathToInputDir = moduleDirectory + "/input/" 

28pathToOutputDir = moduleDirectory + "/output/" 

29 

30try: 

31 shutil.rmtree(pathToOutputDir) 

32except: 

33 pass 

34# COPY INPUT TO OUTPUT DIR 

35shutil.copytree(pathToInputDir, pathToOutputDir) 

36 

37# Recursively create missing directories 

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

39 os.makedirs(pathToOutputDir) 

40 

41settings["atel-directory"] = pathToOutputDir + "atel-directory" 

42 

43def drop_database_tables( 

44 dbConn, 

45 log): 

46 log.debug('starting the ``drop_database_tables`` function') 

47 

48 from fundamentals.mysql import writequery 

49 sqlQuery = """ 

50 drop table if exists atel_coordinates; 

51 drop table if exists atel_names; 

52 drop table if exists atel_fullcontent; 

53 """ % locals() 

54 writequery( 

55 log=log, 

56 sqlQuery=sqlQuery, 

57 dbConn=dbConn 

58 ) 

59 

60 log.debug('completed the ``drop_database_tables`` function') 

61 return None 

62drop_database_tables(dbConn, log) 

63 

64class test_mysql(unittest.TestCase): 

65 

66 def test_01_atels_to_database_function(self): 

67 

68 from atelParser import mysql 

69 parser = mysql( 

70 log=log, 

71 settings=settings 

72 ) 

73 parser.atels_to_database() 

74 

75 def test_02_parse_atels_function(self): 

76 

77 from atelParser import mysql 

78 parser = mysql( 

79 log=log, 

80 settings=settings 

81 ) 

82 parser.parse_atels() 

83 

84 def test_03_update_htm_function(self): 

85 

86 from atelParser import mysql 

87 parser = mysql( 

88 log=log, 

89 settings=settings 

90 ) 

91 parser.populate_htm_columns() 

92 

93 def test_04_mysql_function_exception(self): 

94 

95 from atelParser import mysql 

96 try: 

97 this = mysql( 

98 log=log, 

99 settings=settings, 

100 fakeKey="break the code" 

101 ) 

102 this.get() 

103 assert False 

104 except Exception as e: 

105 assert True 

106 print(str(e)) 

107 

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

109 

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