Skip to content

Commit

Permalink
Coverage for zlogintegration.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Oct 26, 2017
1 parent 56e7af2 commit b147a0c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
33 changes: 33 additions & 0 deletions src/zope/server/tests/test_zlogintegration.py
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""
Tests for zlogintegration.py
"""

import unittest

class TestLogInfo(unittest.TestCase):

def test_patched(self):
from zope.server import zlogintegration
import asyncore

# dispatcher is a class, so this becomes an unbound method
# on Python 2
dispatcher_info = asyncore.dispatcher.log_info
dispatcher_info = getattr(dispatcher_info, '__func__', dispatcher_info)
self.assertEqual(dispatcher_info,
zlogintegration.log_info)

def test_log_info(self):
from zope.server import zlogintegration
from zope.testing.loggingsupport import InstalledHandler

handler = InstalledHandler('zope.server')
try:
zlogintegration.log_info(None, "Some Info")
finally:
handler.uninstall()

self.assertEqual(1, len(handler.records))
self.assertEqual("Some Info", str(handler.records[0].getMessage()))
18 changes: 15 additions & 3 deletions src/zope/server/zlogintegration.py
Expand Up @@ -16,7 +16,7 @@
As a side effect of importing this module, asyncore's logging will be
redirected to the logging module.
"""

import asyncore
import logging

logger = logging.getLogger("zope.server")
Expand All @@ -30,5 +30,17 @@
def log_info(self, message, type='info'):
logger.log(severity.get(type, logging.INFO), message)

import asyncore
asyncore.dispatcher.log_info = log_info

_orig_log_info = asyncore.dispatcher.log_info

def setUp():
asyncore.dispatcher.log_info = log_info

setUp()

try:
from zope.testing.cleanup import addCleanUp
except ImportError: # pragma: no cover
pass
else:
addCleanUp(setUp)

0 comments on commit b147a0c

Please sign in to comment.