[Python-checkins] cpython: test_logging coverage improvements.

vinay.sajip python-checkins at python.org
Wed Apr 27 12:31:42 CEST 2011


http://hg.python.org/cpython/rev/fbac8f321937
changeset:   69593:fbac8f321937
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Wed Apr 27 11:31:14 2011 +0100
summary:
  test_logging coverage improvements.

files:
  Lib/logging/handlers.py  |   4 +-
  Lib/test/test_logging.py |  46 ++++++++++++++++++++++++++-
  2 files changed, 46 insertions(+), 4 deletions(-)


diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -713,10 +713,10 @@
         self.socktype = socktype
 
         if isinstance(address, str):
-            self.unixsocket = 1
+            self.unixsocket = True
             self._connect_unixsocket(address)
         else:
-            self.unixsocket = 0
+            self.unixsocket = False
             self.socket = socket.socket(socket.AF_INET, socktype)
             if socktype == socket.SOCK_STREAM:
                 self.socket.connect(address)
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -508,8 +508,50 @@
         self.assertEqual(h.name, 'anothergeneric')
         self.assertRaises(NotImplementedError, h.emit, None)
 
-    def test_abc(self):
-        pass
+    def test_builtin_handlers(self):
+        # 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):
     def write(self, data):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list