mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-103606: Improve error message from logging.config.FileConfig (GH-103628) (#104687)
* gh-103606: Improve error message from logging.config.FileConfig (GH-103628)
(cherry picked from commit 152227b569
)
plus backport the followup exception change fix to that in #104701
This commit is contained in:
parent
e033edab12
commit
2ade563abc
3 changed files with 61 additions and 6 deletions
|
@ -1645,6 +1645,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(RuntimeError, 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(RuntimeError, 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("""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue