Commit 5ebd3daa authored by Jerry's avatar Jerry
Browse files

Add unittest shell script

Add __init__ function to RotatingFileHandler class



git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac176@2006 e5f2f494-b856-4b98-b285-d166d9295462
parent e50d232a
......@@ -437,6 +437,7 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
src/lib/config/tests/data_def_unittests_config.h
src/lib/python/isc/config/tests/config_test
src/lib/python/isc/cc/tests/cc_test
src/lib/python/isc/log/tests/log_test
src/lib/dns/gen-rdatacode.py
src/lib/dns/tests/testdata/gen-wiredata.py
], [
......
......@@ -4,3 +4,5 @@ python_PYTHON = __init__.py log.py
pythondir = $(pyexecdir)/isc/log
pytest:
$(SHELL) tests/log_test
......@@ -37,6 +37,10 @@ formatter = logging.Formatter("%(name)s: %(levelname)s: %(message)s")
time_formatter = logging.Formatter("%(asctime)s: %(name)s: %(levelname)s: %(message)s")
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0):
super(RotatingFileHandler, self).__init__(filename, mode, maxBytes,
backupCount, encoding, delay)
"""
RotatingFileHandler: replace RotatingFileHandler with a custom handler
"""
......@@ -44,7 +48,7 @@ class RotatingFileHandler(logging.handlers.RotatingFileHandler):
"""
Rewrite RotatingFileHandler.shouldRollover.
If the log file is deleted at run-time, a new file will be created.
If the log file is deleted at runtime, a new file will be created.
"""
dfn = self.baseFilename
if (self.stream) and (not os.path.exists(dfn)): #Is log file exist?
......@@ -81,7 +85,7 @@ class SLHandler(logging.Handler):
If facility is not specified, LOG_USER is used.
"""
super(SLHandler, self).__init__(self)
super(SLHandler, self).__init__()
self.ident = ident
self.logopt = logopt
self.facility = facility
......@@ -118,8 +122,8 @@ class ModuleLogger(logging.getLoggerClass()):
Override logging.logger behaviour
"""
def __init__(self, log_name, log_file,
severity = 'debug', backup_count = 0, max_bytes = 0,
log_to_console = True):
severity='debug', backup_count=0, max_bytes=0,
log_to_console=True):
"""
Initializes the logger with some specific parameters
......@@ -164,8 +168,7 @@ class ModuleLogger(logging.getLoggerClass()):
if(log_file != 0 and log_file != ''):
try:
self.rotating_handler = RotatingFileHandler(filename = log_file,
maxBytes = max_bytes,
backupCount = backup_count)
maxBytes = max_bytes, backupCount = backup_count)
except IOError:
self.rotating_handler = None
return
......
......@@ -7,6 +7,6 @@ PYCOVERAGE = $(PYTHON)
check-local:
for pytest in $(PYTESTS) ; do \
echo Running test: $$pytest ; \
env PYTHONPATH=$(abs_top_srcdir)/src/lib/python \
env PYTHONPATH=$(abs_top_srcdir)/src/lib/python::$(abs_top_builddir)/src/lib/python/isc/log \
$(PYCOVERAGE) $(abs_srcdir)/$$pytest ; \
done
#! /bin/sh
# Copyright (C) 2010 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
PYTHON_EXEC=${PYTHON_EXEC:-@PYTHON@}
export PYTHON_EXEC
TEST_PATH=@abs_top_srcdir@/src/lib/python/isc/log/tests
PYTHONPATH=@abs_top_srcdir@/src/lib/python
export PYTHONPATH
cd ${TEST_PATH}
exec ${PYTHON_EXEC} -O log_test.py $*
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