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""" 

2*Unit testing tools* 

3""" 

4from fundamentals import utKit 

5 

6# OVERRIDES 

7 

8class utKit(utKit): 

9 """ 

10 *Override dryx utKit* 

11 """ 

12 # Variable Data Atrributes 

13 

14 # Override Variable Data Atrributes 

15 # Initialisation 

16 def __init__( 

17 self, 

18 moduleDirectory, 

19 dbConn=False 

20 ): 

21 self.moduleDirectory = moduleDirectory 

22 # x-self-arg-tmpx 

23 

24 # SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

25 self.pathToInputDir = moduleDirectory + "/input/" 

26 self.pathToOutputDir = moduleDirectory + "/output/" 

27 

28 # SETUP LOGGING 

29 self.loggerConfig = """ 

30 version: 1 

31 formatters: 

32 file_style: 

33 format: '* %(asctime)s - %(name)s - %(levelname)s (%(filename)s > %(funcName)s > %(lineno)d) - %(message)s ' 

34 datefmt: '%Y/%m/%d %H:%M:%S' 

35 console_style: 

36 format: '* %(asctime)s - %(levelname)s: %(filename)s:%(funcName)s:%(lineno)d > %(message)s' 

37 datefmt: '%H:%M:%S' 

38 html_style: 

39 format: '<div id="row" class="%(levelname)s"><span class="date">%(asctime)s</span> <span class="label">file:</span><span class="filename">%(filename)s</span> <span class="label">method:</span><span class="funcName">%(funcName)s</span> <span class="label">line#:</span><span class="lineno">%(lineno)d</span> <span class="pathname">%(pathname)s</span> <div class="right"><span class="message">%(message)s</span><span class="levelname">%(levelname)s</span></div></div>' 

40 datefmt: '%Y-%m-%d <span class= "time">%H:%M <span class= "seconds">%Ss</span></span>' 

41 handlers: 

42 console: 

43 class: logging.StreamHandler 

44 level: DEBUG 

45 formatter: console_style 

46 stream: ext://sys.stdout 

47 root: 

48 level: DEBUG 

49 handlers: [console]""" 

50 

51 # Override Variable Data Atrributes 

52 self.dbConfig = False 

53 if dbConn: 

54 self.dbConfig = """ 

55 version: 1 

56 db: dryx_unit_testing 

57 host: localhost 

58 user: unittesting 

59 password: utpass 

60 """ 

61 

62 return 

63 

64 def get_project_root(self): 

65 """ 

66 *Get the root of the `python` package - useful for getting files in the root directory of a project* 

67 

68 **Return** 

69 

70 - ``rootPath`` -- the root path of a project 

71  

72 """ 

73 import os 

74 rootPath = os.path.dirname(__file__) 

75 

76 return rootPath 

77 

78 def refresh_database(self): 

79 """ 

80 *Refresh the unit test database* 

81 """ 

82 from fundamentals.mysql import directory_script_runner 

83 from fundamentals import tools 

84 packageDirectory = self.get_project_root() 

85 su = tools( 

86 arguments={"settingsFile": packageDirectory + 

87 "/test_settings.yaml"}, 

88 docString=__doc__, 

89 logLevel="DEBUG", 

90 options_first=False, 

91 projectName=None, 

92 defaultSettingsFile=False 

93 ) 

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

95 directory_script_runner( 

96 log=log, 

97 pathToScriptDirectory=packageDirectory + "/tests/input", 

98 dbConn=dbConn, 

99 successRule=None, 

100 failureRule=None 

101 )