Skip to content

Commit

Permalink
Closes python#29220: Fixed regression in logging.getLevelName().
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed Jan 11, 2017
1 parent 231d1f3 commit 8b866d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ 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 None:
result = _nameToLevel.get(level)
if result is None:
result = "Level %s" % level
return result

def addLevelName(level, levelName):
"""
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ def test_regression_22386(self):
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), '')

def test_issue27935(self):
fatal = logging.getLevelName('FATAL')
self.assertEqual(fatal, logging.FATAL)
Expand Down

0 comments on commit 8b866d5

Please sign in to comment.