mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
test_logging coverage improvements.
This commit is contained in:
parent
86a96cee23
commit
5a35b06d5e
2 changed files with 46 additions and 4 deletions
|
|
@ -713,10 +713,10 @@ class SysLogHandler(logging.Handler):
|
||||||
self.socktype = socktype
|
self.socktype = socktype
|
||||||
|
|
||||||
if isinstance(address, str):
|
if isinstance(address, str):
|
||||||
self.unixsocket = 1
|
self.unixsocket = True
|
||||||
self._connect_unixsocket(address)
|
self._connect_unixsocket(address)
|
||||||
else:
|
else:
|
||||||
self.unixsocket = 0
|
self.unixsocket = False
|
||||||
self.socket = socket.socket(socket.AF_INET, socktype)
|
self.socket = socket.socket(socket.AF_INET, socktype)
|
||||||
if socktype == socket.SOCK_STREAM:
|
if socktype == socket.SOCK_STREAM:
|
||||||
self.socket.connect(address)
|
self.socket.connect(address)
|
||||||
|
|
|
||||||
|
|
@ -508,8 +508,50 @@ class HandlerTest(BaseTest):
|
||||||
self.assertEqual(h.name, 'anothergeneric')
|
self.assertEqual(h.name, 'anothergeneric')
|
||||||
self.assertRaises(NotImplementedError, h.emit, None)
|
self.assertRaises(NotImplementedError, h.emit, None)
|
||||||
|
|
||||||
def test_abc(self):
|
def test_builtin_handlers(self):
|
||||||
pass
|
# We can't actually *use* too many handlers in the tests,
|
||||||
|
# but we can try instantiating them with various options
|
||||||
|
if sys.platform in ('linux2', 'darwin'):
|
||||||
|
for existing in (True, False):
|
||||||
|
fd, fn = tempfile.mkstemp()
|
||||||
|
os.close(fd)
|
||||||
|
if not existing:
|
||||||
|
os.unlink(fn)
|
||||||
|
h = logging.handlers.WatchedFileHandler(fn, delay=True)
|
||||||
|
if existing:
|
||||||
|
self.assertNotEqual(h.dev, -1)
|
||||||
|
self.assertNotEqual(h.ino, -1)
|
||||||
|
else:
|
||||||
|
self.assertEqual(h.dev, -1)
|
||||||
|
self.assertEqual(h.ino, -1)
|
||||||
|
h.close()
|
||||||
|
if existing:
|
||||||
|
os.unlink(fn)
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
sockname = '/var/run/log'
|
||||||
|
else:
|
||||||
|
sockname = '/dev/log'
|
||||||
|
h = logging.handlers.SysLogHandler(sockname)
|
||||||
|
self.assertEqual(h.facility, h.LOG_USER)
|
||||||
|
self.assertTrue(h.unixsocket)
|
||||||
|
h.close()
|
||||||
|
h = logging.handlers.SMTPHandler('localhost', 'me', 'you', 'Log')
|
||||||
|
self.assertEqual(h.toaddrs, ['you'])
|
||||||
|
h.close()
|
||||||
|
for method in ('GET', 'POST', 'PUT'):
|
||||||
|
if method == 'PUT':
|
||||||
|
self.assertRaises(ValueError, logging.handlers.HTTPHandler,
|
||||||
|
'localhost', '/log', method)
|
||||||
|
else:
|
||||||
|
h = logging.handlers.HTTPHandler('localhost', '/log', method)
|
||||||
|
h.close()
|
||||||
|
h = logging.handlers.BufferingHandler(0)
|
||||||
|
r = logging.makeLogRecord({})
|
||||||
|
self.assertTrue(h.shouldFlush(r))
|
||||||
|
h.close()
|
||||||
|
h = logging.handlers.BufferingHandler(1)
|
||||||
|
self.assertFalse(h.shouldFlush(r))
|
||||||
|
h.close()
|
||||||
|
|
||||||
class BadStream(object):
|
class BadStream(object):
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue