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 

8 

9class utKit(utKit): 

10 """ 

11 *Override dryx utKit* 

12 """ 

13 # Variable Data Atrributes 

14 

15 # Override Variable Data Atrributes 

16 # Initialisation 

17 def __init__( 

18 self, 

19 moduleDirectory, 

20 dbConn=False 

21 ): 

22 self.moduleDirectory = moduleDirectory 

23 # x-self-arg-tmpx 

24 

25 # SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

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

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

28 

29 # SETUP LOGGING 

30 self.loggerConfig = """ 

31 version: 1 

32 formatters: 

33 file_style: 

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

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

36 console_style: 

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

38 datefmt: '%H:%M:%S' 

39 html_style: 

40 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>' 

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

42 handlers: 

43 console: 

44 class: logging.StreamHandler 

45 level: DEBUG 

46 formatter: console_style 

47 stream: ext://sys.stdout 

48 root: 

49 level: DEBUG 

50 handlers: [console]""" 

51 

52 # Override Variable Data Atrributes 

53 self.dbConfig = False 

54 if dbConn: 

55 self.dbConfig = """ 

56 version: 1 

57 db: dryx_unit_testing 

58 host: localhost 

59 user: unittesting 

60 password: utpass 

61 """ 

62 

63 return 

64 

65 def get_project_root(self): 

66 """ 

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

68 

69 **Return** 

70 

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

72 

73 """ 

74 import os 

75 rootPath = os.path.dirname(__file__) 

76 

77 return rootPath 

78 

79 def refresh_database(self): 

80 """ 

81 *Refresh the unit test database* 

82 """ 

83 from fundamentals.mysql import directory_script_runner 

84 from fundamentals import tools 

85 packageDirectory = self.get_project_root() 

86 su = tools( 

87 arguments={"settingsFile": packageDirectory + 

88 "/test_settings.yaml"}, 

89 docString=__doc__, 

90 logLevel="DEBUG", 

91 options_first=False, 

92 projectName=None, 

93 defaultSettingsFile=False 

94 ) 

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

96 directory_script_runner( 

97 log=log, 

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

99 dbConn=dbConn, 

100 successRule=None, 

101 failureRule=None 

102 ) 

103 # DATABASE IMPORT WAS STALLING UNITTESTS 

104 import time 

105 time.sleep(20)