diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/logging/__init__.py | 5 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 8 |
2 files changed, 12 insertions, 1 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 7865b71..3538f06 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -37,7 +37,7 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR', 'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass', 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'shutdown', 'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory', - 'lastResort', 'raiseExceptions'] + 'lastResort', 'raiseExceptions', 'getLevelNamesMapping'] import threading @@ -116,6 +116,9 @@ _nameToLevel = { 'NOTSET': NOTSET, } +def getLevelNamesMapping(): + return _nameToLevel.copy() + def getLevelName(level): """ Return the textual or numeric representation of logging level 'level'. diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index ee00a32..6d11190 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -4390,6 +4390,14 @@ class ModuleLevelMiscTest(BaseTest): self.assertNotIn("Cannot recover from stack overflow.", err) self.assertEqual(rc, 1) + def test_get_level_names_mapping(self): + mapping = logging.getLevelNamesMapping() + self.assertEqual(logging._nameToLevel, mapping) # value is equivalent + self.assertIsNot(logging._nameToLevel, mapping) # but not the internal data + new_mapping = logging.getLevelNamesMapping() # another call -> another copy + self.assertIsNot(mapping, new_mapping) # verify not the same object as before + self.assertEqual(mapping, new_mapping) # but equivalent in value + class LogRecordTest(BaseTest): def test_str_rep(self): |