diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2016-07-22 17:23:04 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2016-07-22 17:23:04 (GMT) |
commit | 638e6220557db50b01653b410eb12f11b9b8ab1c (patch) | |
tree | b685830fe324decdb9c7a5dc68abb31ccd32c617 /Lib/test | |
parent | d3afb62b8fb38417c3f0bf6873ed64bd9efd8e43 (diff) | |
download | cpython-638e6220557db50b01653b410eb12f11b9b8ab1c.zip cpython-638e6220557db50b01653b410eb12f11b9b8ab1c.tar.gz cpython-638e6220557db50b01653b410eb12f11b9b8ab1c.tar.bz2 |
Closes #27493: accepted Path objects in file handlers for logging.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_logging.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 9e9a439..e998f60 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 @@ -575,6 +576,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)) + os.unlink(fn) + h.close() + @unittest.skipIf(os.name == 'nt', 'WatchedFileHandler not appropriate for Windows.') @unittest.skipUnless(threading, 'Threading required for this test.') def test_race(self): |