Commit 15fb873c authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

transfer

parent 19b7893f
.*.swp
*.pyc
#!/usr/bin/env python
"""Unit tests for OperationalLogging."""
import unittest
from nose.tools import raises, eq_
import tempfile
import os
import os.path
import logging
import shutil
import atexit
import StringIO
import OperationalLogger as OpLog
import OperationalMail as OpMail
class TestExit(unittest.TestCase):
ab_diff = "1c1\n< alpha\n---\n> beta\n"
def setUp(self):
print '\n\n'
self.temp_dir = tempfile.mkdtemp()
self.log_dir = tempfile.mkdtemp()
self.file_a = os.path.join(self.temp_dir, 'a')
self.file_b = os.path.join(self.temp_dir, 'b')
with open(self.file_a, 'w') as f:
f.write('alpha\n')
with open(self.file_b, 'w') as f:
f.write('beta\n')
OpLog.setup(log_root_dir=self.log_dir)
def tearDown(self):
shutil.rmtree(self.temp_dir)
print '\n\n'
def test_exit_handler_no_rcpts(self):
logging.error("exit handler test no rcpts")
s = StringIO.StringIO()
temp_buffer = logging.StreamHandler(s)
h = logging.getLogger().addHandler(temp_buffer)
atexit._run_exitfuncs()
assert "No recipients found. Email not sent" in s.getvalue()
logging.getLogger().removeHandler(h)
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
"""Unit tests for OperationalLogging."""
import unittest
from nose.tools import raises, eq_
import tempfile
import os
import os.path
import logging
import shutil
import atexit
import StringIO
import OperationalLogger as OpLog
import OperationalMail as OpMail
class TestSub(unittest.TestCase):
ab_diff = "1c1\n< alpha\n---\n> beta\n"
def setUp(self):
print '\n\n'
self.temp_dir = tempfile.mkdtemp()
self.log_dir = tempfile.mkdtemp()
self.file_a = os.path.join(self.temp_dir, 'a')
self.file_b = os.path.join(self.temp_dir, 'b')
with open(self.file_a, 'w') as f:
f.write('alpha\n')
with open(self.file_b, 'w') as f:
f.write('beta\n')
OpLog.setup(log_root_dir=self.log_dir, notify={'ERROR': ['tcappallo@veriskclimate.com']}, from_address='nosetest@aer.com')
def tearDown(self):
shutil.rmtree(self.temp_dir)
print "logdir =", self.log_dir
print '\n\n'
def test_log_shell(self):
logging.info('Beginning some code...')
a = 1 + 2
logging.debug('a = %d', a)
logging.error('Triggering an error.')
OpLog.log_shell(['python', 'sub.py'])
logging.info('Finishing code.')
def test_log_call(self):
logging.info('Beginning some code...')
a = 1 + 2
logging.debug('a = %d', a)
logging.error('Triggering an error.')
logging.info('Importing sub...')
import sub
logging.info('Finishing code.')
if __name__ == '__main__':
unittest.main()
import logging
import OperationalLogger as OpLog
logging.basicConfig()
logging.warning('I am a warning.')
logging.critical('This is critical!')
OpLog.long_info("This is a\nmultiline\nlog message.")
print "This is going to stdout."
logging.info("And now I'm done.")
{
"notify": {
"DEBUG": ["tcappallo@veriskclimate.com"]
},
"log_format_console": "BLAHBLAH >> ",
"log_root_dir": "test_log_dir"
}
[2015-08-19 19:07:45][ INFO][p30636][OperationalLogger.py:243] Logging output from: setup.py nosetests
[2015-08-19 19:09:11][ INFO][p30875][OperationalLogger.py:243] Logging output from: setup.py nosetests
[2015-08-19 19:09:11][ INFO][p30875][OperationalLogger.py:244] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-08-19 19:09:11][ INFO][p30875][OperationalLogger.py:245] Process id 30875, parent process id 26916
[2015-08-19 19:09:11][ INFO][p30875][OperationalLogger.py:246] ------------------------------------------------------------
[2015-08-19 19:09:11][ INFO][p30875][TestLoad.py:33] This is an info.
[2015-08-19 19:11:58][ INFO][p31951][OperationalLogger.py:244] Logging output from: setup.py nosetests
[2015-08-19 19:11:58][ INFO][p31951][OperationalLogger.py:245] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-08-19 19:11:58][ INFO][p31951][OperationalLogger.py:246] Process id 31951, parent process id 26916
[2015-08-19 19:11:58][ INFO][p31951][OperationalLogger.py:247] ------------------------------------------------------------
[2015-08-19 19:11:58][ INFO][p31951][TestLoad.py:33] This is an info.
[2015-08-28 11:14:27][ INFO][p14383][OperationalLogger.py:256] Logging output from: setup.py nosetests
[2015-08-28 11:14:27][ INFO][p14383][OperationalLogger.py:257] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-08-28 11:14:27][ INFO][p14383][OperationalLogger.py:258] Process id 14383, parent process id 26916
[2015-08-28 11:14:27][ INFO][p14383][OperationalLogger.py:259] ------------------------------------------------------------
[2015-08-28 11:14:27][ INFO][p14383][TestLoad.py:33] This is an info.
[2015-09-01 11:31:14][ INFO][p11505][OperationalLogger.py:258] Logging output from: setup.py nosetests
[2015-09-01 11:31:14][ INFO][p11505][OperationalLogger.py:259] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:31:14][ INFO][p11505][OperationalLogger.py:260] Process id 11505, parent process id 26916
[2015-09-01 11:31:14][ INFO][p11505][OperationalLogger.py:261] ------------------------------------------------------------
[2015-09-01 11:31:14][ INFO][p11505][TestLoad.py:33] This is an info.
[2015-09-01 11:32:43][ INFO][p11565][OperationalLogger.py:258] Logging output from: setup.py nosetests
[2015-09-01 11:32:43][ INFO][p11565][OperationalLogger.py:259] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:32:43][ INFO][p11565][OperationalLogger.py:260] Process id 11565, parent process id 26916
[2015-09-01 11:32:43][ INFO][p11565][OperationalLogger.py:261] ------------------------------------------------------------
[2015-09-01 11:32:43][ INFO][p11565][TestLoad.py:33] This is an info.
[2015-09-01 11:33:20][ INFO][p11603][OperationalLogger.py:258] Logging output from: setup.py nosetests
[2015-09-01 11:33:20][ INFO][p11603][OperationalLogger.py:259] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:33:20][ INFO][p11603][OperationalLogger.py:260] Process id 11603, parent process id 26916
[2015-09-01 11:33:20][ INFO][p11603][OperationalLogger.py:261] ------------------------------------------------------------
[2015-09-01 11:33:20][ INFO][p11603][TestLoad.py:33] This is an info.
[2015-09-01 11:34:00][ INFO][p11652][OperationalLogger.py:258] Logging output from: setup.py nosetests
[2015-09-01 11:34:00][ INFO][p11652][OperationalLogger.py:259] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:34:00][ INFO][p11652][OperationalLogger.py:260] Process id 11652, parent process id 26916
[2015-09-01 11:34:00][ INFO][p11652][OperationalLogger.py:261] ------------------------------------------------------------
[2015-09-01 11:34:00][ INFO][p11652][TestLoad.py:33] This is an info.
[2015-09-01 11:38:54][ INFO][p11758][OperationalLogger.py:258] Logging output from: setup.py nosetests
[2015-09-01 11:38:54][ INFO][p11758][OperationalLogger.py:259] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:38:54][ INFO][p11758][OperationalLogger.py:260] Process id 11758, parent process id 26916
[2015-09-01 11:38:54][ INFO][p11758][OperationalLogger.py:261] ------------------------------------------------------------
[2015-09-01 11:38:54][ INFO][p11758][TestLoad.py:33] This is an info.
[2015-09-01 11:42:02][ INFO][p11851][OperationalLogger.py:260] Logging output from: setup.py nosetests
[2015-09-01 11:42:02][ INFO][p11851][OperationalLogger.py:261] Log writing to: /nas/home/tcappall/prepare/OperationalLogging/lib/test_log_dir/setup.log
[2015-09-01 11:42:02][ INFO][p11851][OperationalLogger.py:262] Process id 11851, parent process id 26916
[2015-09-01 11:42:02][ INFO][p11851][OperationalLogger.py:263] ------------------------------------------------------------
[2015-09-01 11:42:02][ INFO][p11851][TestLoad.py:33] This is an info.
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