Commit 2c0024ba authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

improve tests

parent d7e626f3
......@@ -27,11 +27,10 @@ def __exit_handler(logger, notify):
addresses = notify['ERROR']
if logger.has_critical():
addresses = addresses.extend(notify['CRITICAL'])
addresses = list(set(addresses))
if not addresses:
logging.warning('No recipients found. Email not sent')
else:
addresses = list(set(addresses))
logger.email_log(addresses)
else:
logging.info('No errors found. Email not sent')
......@@ -138,7 +137,7 @@ class OperationalLogger:
if from_address is None:
from_address = self.__from_address
logging.info("Sending log email to %s", addresses)
message = "<br />\n".join([__class__.__colorize(line) for line in self.__error_buffer.getvalue().split('\n')])
message = "<br />\n".join([self.__class__.__colorize(line) for line in self.__error_buffer.getvalue().split('\n')])
OperationalMail.send_status(subject='Errors detected {}:{}'.format(self.__server_name,
os.path.basename(sys.argv[0])),
message=message, to_list=addresses, from_address=from_address,
......@@ -147,11 +146,11 @@ class OperationalLogger:
@staticmethod
def __colorize(line):
"""Add HTML markup for severity of log message."""
if '[CRITICAL]' in line:
if 'CRITICAL' in line:
return '<span style="color:red">{}</span>'.format(line)
if '[ERROR]' in line:
if 'ERROR' in line:
return '<span style="color:red">{}</span>'.format(line)
if '[WARNING]' in line:
if 'WARNING' in line:
return '<span style="color:blue">{}</span>'.format(line)
return line
......@@ -278,7 +277,7 @@ def log_shell(arg_list, raise_err=False, return_output=False, **kwargs):
return_output: (like subprocess.check_output) returns any output
from shell call instead of the exit code
"""
logging.info('Starting child process of ppid={}'.format(os.getppid()))
logging.info('Spawning child process from pid={}'.format(os.getpid()))
logging.info('Executing: {}'.format(' '.join(arg_list)))
try:
my_name = os.path.basename(inspect.getfile(inspect.currentframe()))
......@@ -315,25 +314,3 @@ def stack_trace(log_level=logging.ERROR):
import traceback
tb = traceback.format_exc()
long_log(log_level, tb)
if __name__ == '__main__':
setup()
test = """Blah
foo
bar
beer
bear
"""
logging.info('Blah')
logging.debug('Fin')
logging.error('An error in testing, oh, no!!')
logging.critical('Put up the Jimsignal!')
logging.error(test)
c = ['diff', 'a', 'b']
log_shell(c)
try:
raise Exception("I AM ERROR.")
except Exception as err:
logging.debug(err)
stack_trace()
......@@ -59,22 +59,3 @@ def send_status(subject, message, to_list, from_address='no-reply@aer.com', repl
server.sendmail(from_address, to_list, mail.as_string())
server.quit()
return
if __name__ == '__main__':
msg = """<P>Test of the OperationalMail module</P>
<P>Let us see if this works.</P>
<UL>
<LI>I am not sure it should</LI>
<LI>Do I really want it to?</LI>
<LI>So many questions.</LI>
</UL>
<P>Fin</P>
"""
default_addresses = ['tcappallo@veriskclimate.com']
send_status('Non-pyProcess Email Module', msg, default_addresses)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment