diff options
author | Prince Roshan <princekrroshan01@gmail.com> | 2023-05-18 04:20:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 04:20:47 (GMT) |
commit | 152227b569c3a9b87fe0483706f704762ced6d75 (patch) | |
tree | 5b0eaf24758bbb4aa37ca53f7a4f40cf7cdbe034 /Lib/test/test_logging.py | |
parent | c5b670efd1e6dabc94b6308734d63f762480b80f (diff) | |
download | cpython-152227b569c3a9b87fe0483706f704762ced6d75.zip cpython-152227b569c3a9b87fe0483706f704762ced6d75.tar.gz cpython-152227b569c3a9b87fe0483706f704762ced6d75.tar.bz2 |
gh-103606: Improve error message from logging.config.FileConfig (GH-103628)
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 9176d8e..ba836a7 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1756,6 +1756,42 @@ class ConfigFileTest(BaseTest): self.apply_config(test_config) self.assertEqual(logging.getLogger().handlers[0].name, 'hand1') + def test_exception_if_confg_file_is_invalid(self): + test_config = """ + [loggers] + keys=root + + [handlers] + keys=hand1 + + [formatters] + keys=form1 + + [logger_root] + handlers=hand1 + + [handler_hand1] + class=StreamHandler + formatter=form1 + + [formatter_form1] + format=%(levelname)s ++ %(message)s + + prince + """ + + file = io.StringIO(textwrap.dedent(test_config)) + self.assertRaises(ValueError, logging.config.fileConfig, file) + + def test_exception_if_confg_file_is_empty(self): + fd, fn = tempfile.mkstemp(prefix='test_empty_', suffix='.ini') + os.close(fd) + self.assertRaises(ValueError, logging.config.fileConfig, fn) + os.remove(fn) + + def test_exception_if_config_file_does_not_exist(self): + self.assertRaises(FileNotFoundError, logging.config.fileConfig, 'filenotfound') + def test_defaults_do_no_interpolation(self): """bpo-33802 defaults should not get interpolated""" ini = textwrap.dedent(""" |