Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4406,6 +4406,29 @@ def test_basic(self):
self.assertTrue(found, msg=msg)


class CachingTest(BaseTest):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add this to an existing test case class rather than adding a separate class just for this one method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll move it to the LoggerTest class

def test_caching(self):
root = self.root_logger
level1 = logging.getLogger("abc")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are loggers, not levels, and the names should reflect that. I understand you're talking about level in the logger hierarchy, but still, the use of level for the loggers is potentially confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will fix

level2 = logging.getLogger("abc.def")

root.setLevel(logging.ERROR)
self.assertEqual(level2._cache, {}) # Cache is empty

self.assertTrue(level2.isEnabledFor(logging.ERROR))
self.assertEqual(level2._cache, {logging.ERROR: True}) # Cache is populated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What values would the logger level cache dict have? Either empty or a level pointing to True? Could there be multiple keys in this dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys are the levels passes to isEnabledFor(), values are always True or False. I can lookup more levels to get a more well-rounded test.

self.assertEqual(root._cache, {}) # Root cache is empty
self.assertTrue(level2.isEnabledFor(logging.ERROR))

level1.setLevel(logging.CRITICAL)
self.assertEqual(level2._cache, {}) # Cache is empty
self.assertEqual(root._cache, {}) # Root cache is empty

self.assertFalse(level2.isEnabledFor(logging.ERROR))
self.assertTrue(root.isEnabledFor(logging.ERROR))
self.assertEqual(root._cache, {logging.ERROR: True}) # Root cache is populated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should do level2.setLevel(logging.NOTSET). and see that the isEnabledFor() for the two loggers and the root logger are as expected.

Also, it makes sense to add some tests for getEffectiveLevel() to ensure that the values are as expected without the presence of caching.


class MiscTestCase(unittest.TestCase):
def test__all__(self):
blacklist = {'logThreads', 'logMultiprocessing',
Expand Down