Coverage for astrocalc/utKit.py : 70%

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
6# OVERRIDES
9class utKit(utKit):
10 """
11 *Override dryx utKit*
12 """
13 # Variable Data Atrributes
15 # Override Variable Data Atrributes
16 # Initialisation
17 def __init__(
18 self,
19 moduleDirectory
20 ):
21 self.moduleDirectory = moduleDirectory
22 # x-self-arg-tmpx
23 # SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA
24 self.pathToInputDir = moduleDirectory + "/input/"
25 self.pathToOutputDir = moduleDirectory + "/output/"
27 # SETUP LOGGING
28 self.loggerConfig = """
29 version: 1
30 formatters:
31 file_style:
32 format: '* %(asctime)s - %(name)s - %(levelname)s (%(filename)s > %(funcName)s > %(lineno)d) - %(message)s '
33 datefmt: '%Y/%m/%d %H:%M:%S'
34 console_style:
35 format: '* %(asctime)s - %(levelname)s: %(filename)s:%(funcName)s:%(lineno)d > %(message)s'
36 datefmt: '%H:%M:%S'
37 html_style:
38 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>'
39 datefmt: '%Y-%m-%d <span class= "time">%H:%M <span class= "seconds">%Ss</span></span>'
40 handlers:
41 console:
42 class: logging.StreamHandler
43 level: DEBUG
44 formatter: console_style
45 stream: ext://sys.stdout
46 root:
47 level: DEBUG
48 handlers: [console]"""
50 # Override Variable Data Atrributes
51 self.dbConfig = """
52 version: 1
53 db: unit_tests
54 host: localhost
55 user: utuser
56 password: utpass
57 loginPath: unittesting
58 """
60 return
62 def get_project_root(self):
63 """
64 *Get the root of the `python` package - useful for getting files in the root directory of a project*
66 **Return**
68 - ``rootPath`` -- the root path of a project
70 """
71 import os
72 rootPath = os.path.dirname(__file__)
74 return rootPath
76 def refresh_database(self):
77 """
78 *Refresh the unit test database*
79 """
80 from fundamentals.mysql import directory_script_runner
81 from fundamentals import tools
82 packageDirectory = self.get_project_root()
83 su = tools(
84 arguments={"settingsFile": packageDirectory +
85 "/test_settings.yaml"},
86 docString=__doc__,
87 logLevel="DEBUG",
88 options_first=False,
89 projectName=None,
90 defaultSettingsFile=False
91 )
92 arguments, settings, log, dbConn = su.setup()
93 directory_script_runner(
94 log=log,
95 pathToScriptDirectory=packageDirectory + "/tests/input",
96 dbConn=dbConn,
97 successRule=None,
98 failureRule=None
99 )