summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-14 09:34:09 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-14 09:34:09 (GMT)
commit8552d1fc8fd37fa03f5ab269f59ce4029afa04dd (patch)
tree431431c65b677682c976afffa197f4173885fb8a /Lib
parentde72692465289b28038fb903e2fd82efa47c72f9 (diff)
downloadcpython-8552d1fc8fd37fa03f5ab269f59ce4029afa04dd.zip
cpython-8552d1fc8fd37fa03f5ab269f59ce4029afa04dd.tar.gz
cpython-8552d1fc8fd37fa03f5ab269f59ce4029afa04dd.tar.bz2
Added test for QueueHandler.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_logging.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 511b2e0..0242dc8 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -31,6 +31,7 @@ import io
import gc
import json
import os
+import queue
import re
import select
import socket
@@ -1760,6 +1761,35 @@ class ChildLoggerTest(BaseTest):
self.assertTrue(c2 is c3)
+class QueueHandlerTest(BaseTest):
+ # Do not bother with a logger name group.
+ expected_log_pat = r"^[\w.]+ -> ([\w]+): ([\d]+)$"
+
+ def setUp(self):
+ BaseTest.setUp(self)
+ self.queue = queue.Queue(-1)
+ self.que_hdlr = logging.handlers.QueueHandler(self.queue)
+ self.que_logger = logging.getLogger('que')
+ self.que_logger.propagate = False
+ self.que_logger.setLevel(logging.WARNING)
+ self.que_logger.addHandler(self.que_hdlr)
+
+ def tearDown(self):
+ self.que_hdlr.close()
+ BaseTest.tearDown(self)
+
+ def test_queue_handler(self):
+ self.que_logger.debug(self.next_message())
+ self.assertRaises(queue.Empty, self.queue.get_nowait)
+ self.que_logger.info(self.next_message())
+ self.assertRaises(queue.Empty, self.queue.get_nowait)
+ msg = self.next_message()
+ self.que_logger.warning(msg)
+ data = self.queue.get_nowait()
+ self.assertTrue(isinstance(data, logging.LogRecord))
+ self.assertEqual(data.name, self.que_logger.name)
+ self.assertEqual((data.msg, data.args), (msg, None))
+
# Set the locale to the platform-dependent default. I have no idea
# why the test does this, but in any case we save the current locale
# first and restore it at the end.
@@ -1769,7 +1799,7 @@ def test_main():
CustomLevelsAndFiltersTest, MemoryHandlerTest,
ConfigFileTest, SocketHandlerTest, MemoryTest,
EncodingTest, WarningsTest, ConfigDictTest, ManagerTest,
- ChildLoggerTest)
+ ChildLoggerTest, QueueHandlerTest)
if __name__ == "__main__":
test_main()