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 import os 

73 rootPath = os.path.dirname(__file__) 

74 

75 return rootPath 

76 

77 def refresh_database(self): 

78 """ 

79 *Refresh the unit test database* 

80 """ 

81 from fundamentals.mysql import directory_script_runner 

82 from fundamentals import tools 

83 packageDirectory = self.get_project_root() 

84 su = tools( 

85 arguments={"settingsFile": packageDirectory + 

86 "/test_settings.yaml"}, 

87 docString=__doc__, 

88 logLevel="DEBUG", 

89 options_first=False, 

90 projectName=None, 

91 defaultSettingsFile=False 

92 ) 

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

94 directory_script_runner( 

95 log=log, 

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

97 dbConn=dbConn, 

98 successRule=None, 

99 failureRule=None 

100 )