Tests for Pecan logging.

This commit is contained in:
Ryan Petrello
2012-03-24 01:30:33 -04:00
parent 1d5418420a
commit ccd177d774
2 changed files with 65 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ from middleware.errordocument import ErrorDocumentMiddleware
from middleware.recursive import RecursiveMiddleware
from middleware.static import StaticFileMiddleware
from configuration import set_config
from configuration import set_config, Config
from configuration import _runtime_conf as conf
from logging.config import dictConfig as load_logging_config
@@ -46,7 +46,8 @@ def make_app(root, static_root=None, logging={}, debug=False,
# Pass logging configuration (if it exists) on to the Python logging module
if logging:
logging = logging.as_dict()
if isinstance(logging, Config):
logging = logging.as_dict()
if 'version' not in logging:
logging['version'] = 1
load_logging_config(logging)

View File

@@ -1073,6 +1073,68 @@ class TestNonCanonical(unittest.TestCase):
assert len(wrapped_apps) == 1
class TestLogging(unittest.TestCase):
def test_logging_setup(self):
class RootController(object):
@expose()
def index(self):
import logging
logging.getLogger('pecantesting').info('HELLO WORLD')
return "HELLO WORLD"
from cStringIO import StringIO
f = StringIO()
app = TestApp(make_app(RootController(), logging={
'loggers': {
'pecantesting': {
'level': 'INFO', 'handlers': ['memory']
}
},
'handlers': {
'memory': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'stream': f
}
}
}))
app.get('/')
assert f.getvalue() == 'HELLO WORLD\n'
def test_logging_setup_with_config_obj(self):
class RootController(object):
@expose()
def index(self):
import logging
logging.getLogger('pecantesting').info('HELLO WORLD')
return "HELLO WORLD"
from cStringIO import StringIO
f = StringIO()
from pecan.configuration import conf_from_dict
app = TestApp(make_app(RootController(), logging=conf_from_dict({
'loggers': {
'pecantesting': {
'level': 'INFO', 'handlers': ['memory']
}
},
'handlers': {
'memory': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'stream': f
}
}
})))
app.get('/')
assert f.getvalue() == 'HELLO WORLD\n'
class TestEngines(unittest.TestCase):
template_path = os.path.join(os.path.dirname(__file__), 'templates')