summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2016-09-08 00:37:03 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2016-09-08 00:37:03 (GMT)
commitdb8f46321f56a9c23ab9ee5f3cee25f35f672e49 (patch)
treedabf5b8eca781bdc49020fa2250555649436f50c /Lib/test
parentef37dfcd841bc1565a3e40bbcd0f5354aa150965 (diff)
downloadcpython-db8f46321f56a9c23ab9ee5f3cee25f35f672e49.zip
cpython-db8f46321f56a9c23ab9ee5f3cee25f35f672e49.tar.gz
cpython-db8f46321f56a9c23ab9ee5f3cee25f35f672e49.tar.bz2
Added back test code lost during merge.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_logging.py72
1 files changed, 71 insertions, 1 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 85344de..e45a982 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -26,6 +26,7 @@ import logging.config
import codecs
import configparser
import datetime
+import pathlib
import pickle
import io
import gc
@@ -308,6 +309,10 @@ class BuiltinLevelsTest(BaseTest):
self.assertEqual(logging.getLevelName('INFO'), logging.INFO)
self.assertEqual(logging.getLevelName(logging.INFO), 'INFO')
+ def test_issue27935(self):
+ fatal = logging.getLevelName('FATAL')
+ self.assertEqual(fatal, logging.FATAL)
+
class BasicFilterTest(BaseTest):
"""Test the bundled Filter class."""
@@ -575,6 +580,29 @@ class HandlerTest(BaseTest):
self.assertFalse(h.shouldFlush(r))
h.close()
+ def test_path_objects(self):
+ """
+ Test that Path objects are accepted as filename arguments to handlers.
+
+ See Issue #27493.
+ """
+ fd, fn = tempfile.mkstemp()
+ os.close(fd)
+ os.unlink(fn)
+ pfn = pathlib.Path(fn)
+ cases = (
+ (logging.FileHandler, (pfn, 'w')),
+ (logging.handlers.RotatingFileHandler, (pfn, 'a')),
+ (logging.handlers.TimedRotatingFileHandler, (pfn, 'h')),
+ )
+ if sys.platform in ('linux', 'darwin'):
+ cases += ((logging.handlers.WatchedFileHandler, (pfn, 'w')),)
+ for cls, args in cases:
+ h = cls(*args)
+ self.assertTrue(os.path.exists(fn))
+ h.close()
+ os.unlink(fn)
+
@unittest.skipIf(os.name == 'nt', 'WatchedFileHandler not appropriate for Windows.')
@unittest.skipUnless(threading, 'Threading required for this test.')
def test_race(self):
@@ -958,7 +986,7 @@ class MemoryHandlerTest(BaseTest):
def setUp(self):
BaseTest.setUp(self)
self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
- self.root_hdlr)
+ self.root_hdlr)
self.mem_logger = logging.getLogger('mem')
self.mem_logger.propagate = 0
self.mem_logger.addHandler(self.mem_hdlr)
@@ -995,6 +1023,36 @@ class MemoryHandlerTest(BaseTest):
self.mem_logger.debug(self.next_message())
self.assert_log_lines(lines)
+ def test_flush_on_close(self):
+ """
+ Test that the flush-on-close configuration works as expected.
+ """
+ self.mem_logger.debug(self.next_message())
+ self.assert_log_lines([])
+ self.mem_logger.info(self.next_message())
+ self.assert_log_lines([])
+ self.mem_logger.removeHandler(self.mem_hdlr)
+ # Default behaviour is to flush on close. Check that it happens.
+ self.mem_hdlr.close()
+ lines = [
+ ('DEBUG', '1'),
+ ('INFO', '2'),
+ ]
+ self.assert_log_lines(lines)
+ # Now configure for flushing not to be done on close.
+ self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
+ self.root_hdlr,
+ False)
+ self.mem_logger.addHandler(self.mem_hdlr)
+ self.mem_logger.debug(self.next_message())
+ self.assert_log_lines(lines) # no change
+ self.mem_logger.info(self.next_message())
+ self.assert_log_lines(lines) # no change
+ self.mem_logger.removeHandler(self.mem_hdlr)
+ self.mem_hdlr.close()
+ # assert that no new lines have been added
+ self.assert_log_lines(lines) # no change
+
class ExceptionFormatter(logging.Formatter):
"""A special exception formatter."""
@@ -4239,6 +4297,17 @@ class NTEventLogHandlerTest(BaseTest):
msg = 'Record not found in event log, went back %d records' % GO_BACK
self.assertTrue(found, msg=msg)
+
+class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ blacklist = {'logThreads', 'logMultiprocessing',
+ 'logProcesses', 'currentframe',
+ 'PercentStyle', 'StrFormatStyle', 'StringTemplateStyle',
+ 'Filterer', 'PlaceHolder', 'Manager', 'RootLogger',
+ 'root'}
+ support.check__all__(self, logging, blacklist=blacklist)
+
+
# 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.
@@ -4256,6 +4325,7 @@ def test_main():
ExceptionTest, SysLogHandlerTest, HTTPHandlerTest,
NTEventLogHandlerTest, TimedRotatingFileHandlerTest,
UnixSocketHandlerTest, UnixDatagramHandlerTest, UnixSysLogHandlerTest,
+ MiscTestCase
]
if hasattr(logging.handlers, 'QueueListener'):
tests.append(QueueListenerTest)