diff options
author | Xtreak <tirkarthi@users.noreply.github.com> | 2018-07-02 08:57:46 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2018-07-02 08:57:46 (GMT) |
commit | 087570af6d5d39b51bdd5e660a53903960e58678 (patch) | |
tree | 44556f42bbe02071a5a6f4f51781762b174ace32 /Lib/test/test_logging.py | |
parent | c6cd164cffedb306a4c6644d9d03072f24da246d (diff) | |
download | cpython-087570af6d5d39b51bdd5e660a53903960e58678.zip cpython-087570af6d5d39b51bdd5e660a53903960e58678.tar.gz cpython-087570af6d5d39b51bdd5e660a53903960e58678.tar.bz2 |
bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008)
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index b3618bd..a3731fa 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1089,6 +1089,7 @@ class ConfigFileTest(BaseTest): """Reading logging config from a .ini-style config file.""" + check_no_resource_warning = support.check_no_resource_warning expected_log_pat = r"^(\w+) \+\+ (\w+)$" # config0 is a standard configuration. @@ -1297,6 +1298,27 @@ class ConfigFileTest(BaseTest): datefmt= """ + # config 8, check for resource warning + config8 = r""" + [loggers] + keys=root + + [handlers] + keys=file + + [formatters] + keys= + + [logger_root] + level=DEBUG + handlers=file + + [handler_file] + class=FileHandler + level=DEBUG + args=("{tempfile}",) + """ + disable_test = """ [loggers] keys=root @@ -1442,6 +1464,29 @@ class ConfigFileTest(BaseTest): # Original logger output is empty. self.assert_log_lines([]) + def test_config8_ok(self): + + def cleanup(h1, fn): + h1.close() + os.remove(fn) + + with self.check_no_resource_warning(): + fd, fn = tempfile.mkstemp(".log", "test_logging-X-") + os.close(fd) + + # Replace single backslash with double backslash in windows + # to avoid unicode error during string formatting + if os.name == "nt": + fn = fn.replace("\\", "\\\\") + + config8 = self.config8.format(tempfile=fn) + + self.apply_config(config8) + self.apply_config(config8) + + handler = logging.root.handlers[0] + self.addCleanup(cleanup, handler, fn) + def test_logger_disabling(self): self.apply_config(self.disable_test) logger = logging.getLogger('some_pristine_logger') @@ -2022,6 +2067,7 @@ class ConfigDictTest(BaseTest): """Reading logging config from a dictionary.""" + check_no_resource_warning = support.check_no_resource_warning expected_log_pat = r"^(\w+) \+\+ (\w+)$" # config0 is a standard configuration. @@ -2896,6 +2942,35 @@ class ConfigDictTest(BaseTest): logging.warning('Exclamation') self.assertTrue(output.getvalue().endswith('Exclamation!\n')) + def test_config15_ok(self): + + def cleanup(h1, fn): + h1.close() + os.remove(fn) + + with self.check_no_resource_warning(): + fd, fn = tempfile.mkstemp(".log", "test_logging-X-") + os.close(fd) + + config = { + "version": 1, + "handlers": { + "file": { + "class": "logging.FileHandler", + "filename": fn + } + }, + "root": { + "handlers": ["file"] + } + } + + self.apply_config(config) + self.apply_config(config) + + handler = logging.root.handlers[0] + self.addCleanup(cleanup, handler, fn) + def setup_via_listener(self, text, verify=None): text = text.encode("utf-8") # Ask for a randomly assigned port (by using port 0) |