Skip to content

Commit

Permalink
Merge pull request #1097 from lsst/u/dhirving/fix-mypy-breakage
Browse files Browse the repository at this point in the history
Fix typing in cliLogTestBase.
  • Loading branch information
dhirving authored Oct 15, 2024
2 parents 86eadf3 + 4a9cb03 commit 6616209
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions python/lsst/daf/butler/tests/cliLogTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import re
import subprocess
import tempfile
import unittest
import unittest.mock
from collections import namedtuple
from collections.abc import Callable
from functools import partial
Expand Down Expand Up @@ -152,8 +152,12 @@ class LsstLogger:
"""

def __init__(self, component: str) -> None:
self.logger = lsstLog.getLogger(component) if lsstLog else None
self.initialLevel = self.logger.getLevel() if lsstLog else None
if lsstLog:
self.logger = lsstLog.getLogger(component)
self.initialLevel = self.logger.getLevel()
else:
self.logger = None
self.initialLevel = None

def runTest(self, cmd: Callable) -> None:
"""Test that the log context manager works with the butler cli.
Expand Down Expand Up @@ -188,6 +192,8 @@ def runTest(self, cmd: Callable) -> None:
self.assertEqual(pyLsstRoot.logger.level, logging.INFO)
self.assertEqual(pyButler.logger.level, pyButler.initialLevel)
if lsstLog is not None:
assert lsstRoot.logger is not None
assert lsstButler.logger is not None
self.assertEqual(lsstRoot.logger.getLevel(), lsstLog.INFO)
# lsstLogLevel can either be the initial level, or uninitialized or
# the defined default value.
Expand Down Expand Up @@ -385,7 +391,7 @@ def testFileLogging(self) -> None:
self.assertIn("DEBUG", records_text[num], str(records_text[num]))
self.assertNotIn("{", records_text[num], str(records_text[num]))

self.assertGreater(len(records), n_records)
self.assertGreater(len(records_text), n_records)

def testLogTty(self) -> None:
"""Verify that log output to terminal can be suppressed."""
Expand Down

0 comments on commit 6616209

Please sign in to comment.