Skip to content

Commit

Permalink
Add tests for logging.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bpepple committed Jun 19, 2024
1 parent f690399 commit 77979c2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import logging
from unittest.mock import MagicMock, patch

import pytest

from metrontagger.logging import init_logging
from metrontagger.settings import MetronTaggerSettings

LOG_FMT = "{asctime} - {name} - {levelname} - {message}"
DATE_FMT = "%Y-%m-%d %H:%M:%S"


def test_init_logging_happy_path(tmp_path):
# Arrange
config = MagicMock(spec=MetronTaggerSettings)
config.get_settings_folder.return_value = tmp_path

# Act
with patch("logging.FileHandler") as mock_file_handler:
init_logging(config)

# Assert
mock_file_handler.assert_called_once_with(str(tmp_path / "metron-tagger.log"))
assert logging.getLogger().level == logging.WARNING


@pytest.mark.parametrize(
("config", "expected_exception"),
[
(None, AttributeError),
(MagicMock(spec=object), AttributeError),
],
ids=["none_config", "invalid_config"],
)
def test_init_logging_error_cases(config, expected_exception):
# Act
with pytest.raises(expected_exception):
init_logging(config)

0 comments on commit 77979c2

Please sign in to comment.