Skip to content

Commit

Permalink
test: Again
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Jan 3, 2025
1 parent 1ebc04e commit 44e1425
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
9 changes: 1 addition & 8 deletions anta/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ def setup_logging(level: LogLevel = Log.INFO, file: Path | None = None) -> None:

def _get_file_handler(logger_instance: logging.Logger, file: Path) -> logging.FileHandler | None:
"""Return the FileHandler if present."""
# ruff: noqa: T201
for handler in logger_instance.handlers:
if isinstance(handler, logging.FileHandler):
print(handler.baseFilename)
print(Path(handler.baseFilename))
print(file)

return (
next((handler for handler in logger_instance.handlers if isinstance(handler, logging.FileHandler) and handler.baseFilename == str(file)), None)
next((handler for handler in logger_instance.handlers if isinstance(handler, logging.FileHandler) and Path(handler.baseFilename) == file), None)
if logger_instance.hasHandlers()
else None
)
Expand Down
9 changes: 3 additions & 6 deletions tests/units/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING
from pathlib import Path
from unittest.mock import patch

import pytest

from anta.logger import Log, LogLevel, _get_file_handler, _get_rich_handler, anta_log_exception, exc_to_str, setup_logging, tb_to_str

if TYPE_CHECKING:
from pathlib import Path


@pytest.mark.parametrize(
("level", "path", "debug_value"),
[
pytest.param(Log.INFO, None, False, id="INFO no file"),
pytest.param(Log.DEBUG, None, False, id="DEBUG no file"),
pytest.param(Log.INFO, "/tmp/file.log", False, id="INFO file"),
pytest.param(Log.DEBUG, "/tmp/file.log", False, id="DEBUG file"),
pytest.param(Log.INFO, Path("/tmp/file.log"), False, id="INFO file"),
pytest.param(Log.DEBUG, Path("/tmp/file.log"), False, id="DEBUG file"),
pytest.param(Log.INFO, None, True, id="INFO no file __DEBUG__ set"),
pytest.param(Log.DEBUG, None, True, id="INFO no file __DEBUG__ set"),
],
Expand Down

0 comments on commit 44e1425

Please sign in to comment.