Skip to content

Commit

Permalink
refactor: parametrize test_logging function
Browse files Browse the repository at this point in the history
  • Loading branch information
kreczko committed Jun 12, 2024
1 parent e726118 commit 40e54a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ warn_unreachable = true
module = ["rich.*"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = ["fasthep_logging.*"]
implicit_reexport = true
ignore_missing_imports = true

[tool.coverage]
run.source = ["fasthep_flow"]
port.exclude_lines = [
Expand Down
26 changes: 11 additions & 15 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,23 @@ def test_getLogger() -> None:
logger = m.get_logger("TESTLOGGER")
assert logger.name == "TESTLOGGER"
assert logger.level == m.DEFAULT_LOG_LEVEL
assert logger.TRACE == m.TRACE # type: ignore[attr-defined]
assert logger.TIMING == m.TIMING # type: ignore[attr-defined]
assert logger.TRACE == m.TRACE
assert logger.TIMING == m.TIMING


def test_trace(caplog: pytest.LogCaptureFixture) -> None:
@pytest.mark.parametrize(
("level", "func"),
[(logging.INFO, "info"), (m.TRACE, "trace"), (m.TIMING, "timing")],
)
def test_logging(caplog: pytest.LogCaptureFixture, level: int, func: str) -> None:
logger = m.get_logger("TESTLOGGER")
caplog.set_level(logging.TRACE, logger="TESTLOGGER") # type: ignore[attr-defined]
logger.trace("test") # type: ignore[attr-defined]
assert len(caplog.records) == 1
record = caplog.records[0]
assert record.name == "TESTLOGGER"
assert record.levelname == "TRACE"
assert record.message == "test"
logger.propagate = True
caplog.set_level(level, logger="TESTLOGGER")

getattr(logger, func)("test")

def test_timing(caplog: pytest.LogCaptureFixture) -> None:
logger = m.get_logger("TESTLOGGER")
caplog.set_level(logging.TIMING, logger="TESTLOGGER") # type: ignore[attr-defined]
logger.timing("test") # type: ignore[attr-defined]
assert len(caplog.records) == 1
record = caplog.records[0]
assert record.name == "TESTLOGGER"
assert record.levelname == "TIMING"
assert record.levelname == logging.getLevelName(level)
assert record.message == "test"

0 comments on commit 40e54a2

Please sign in to comment.