summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-11 17:35:36 +0000
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-11 17:35:36 +0000
commite949ac52e0cb36421bf7712eaba1aadedaa301d1 (patch)
tree628953f45056f2bcfb99a9364364089a35435798 /Lib
parent4c79578b758b45ca300314ec53e85101508edc60 (diff)
downloadcpython-e949ac52e0cb36421bf7712eaba1aadedaa301d1.tar.gz
Issue #29220: Improved fix and test.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/__init__.py11
-rw-r--r--Lib/test/test_logging.py8
2 files changed, 16 insertions, 3 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 22744e18b0..6455f39ce8 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -129,9 +129,14 @@ def getLevelName(level):
Otherwise, the string "Level %s" % level is returned.
"""
- # See Issues #22386 and #27937 for why it's this way
- return (_levelToName.get(level) or _nameToLevel.get(level) or
- "Level %s" % level)
+ # See Issues #22386, #27937 and #29220 for why it's this way
+ result = _levelToName.get(level)
+ if result is not None:
+ return result
+ result = _nameToLevel.get(level)
+ if result is not None:
+ return result
+ return "Level %s" % level
def addLevelName(level, levelName):
"""
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 0e70ccd5f0..1c850456b1 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -308,6 +308,14 @@ class BuiltinLevelsTest(BaseTest):
self.assertEqual(logging.getLevelName('INFO'), logging.INFO)
self.assertEqual(logging.getLevelName(logging.INFO), 'INFO')
+ def test_regression_29220(self):
+ """See issue #29220 for more information."""
+ logging.addLevelName(logging.INFO, '')
+ self.addCleanup(logging.addLevelName, logging.INFO, 'INFO')
+ self.assertEqual(logging.getLevelName(logging.INFO), '')
+ self.assertEqual(logging.getLevelName(logging.NOTSET), 'NOTSET')
+ self.assertEqual(logging.getLevelName('NOTSET'), logging.NOTSET)
+
class BasicFilterTest(BaseTest):
"""Test the bundled Filter class."""