From dddfb9c9913c441498c1387c9a6e76795301157b Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Tue, 21 Jan 2025 10:07:26 +0100 Subject: [PATCH] Remove structlog (#119) * Replace structlog with stdlib logger * Uninstall structlog --- meldingen_core/actions/melding.py | 5 ++--- poetry.lock | 22 ++-------------------- pyproject.toml | 1 - tests/test_actions/test_melding_actions.py | 14 ++++++++------ 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/meldingen_core/actions/melding.py b/meldingen_core/actions/melding.py index 8013dd8..435637e 100644 --- a/meldingen_core/actions/melding.py +++ b/meldingen_core/actions/melding.py @@ -1,9 +1,8 @@ +import logging from abc import ABCMeta, abstractmethod from datetime import datetime, timedelta from typing import Any, Generic, TypeVar, override -import structlog - from meldingen_core.actions.base import BaseCreateAction, BaseCRUDAction, BaseListAction, BaseRetrieveAction from meldingen_core.classification import ClassificationNotFoundException, Classifier from meldingen_core.exceptions import NotFoundException @@ -12,7 +11,7 @@ from meldingen_core.statemachine import BaseMeldingStateMachine, MeldingTransitions from meldingen_core.token import BaseTokenGenerator, TokenVerifier -log = structlog.get_logger() +log = logging.getLogger(__name__) T = TypeVar("T", bound=Melding) T_co = TypeVar("T_co", covariant=True, bound=Melding) diff --git a/poetry.lock b/poetry.lock index f25bdd8..bfa5219 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. [[package]] name = "aiodns" @@ -2176,24 +2176,6 @@ files = [ {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, ] -[[package]] -name = "structlog" -version = "24.4.0" -description = "Structured Logging for Python" -optional = false -python-versions = ">=3.8" -groups = ["main"] -files = [ - {file = "structlog-24.4.0-py3-none-any.whl", hash = "sha256:597f61e80a91cc0749a9fd2a098ed76715a1c8a01f73e336b746504d1aad7610"}, - {file = "structlog-24.4.0.tar.gz", hash = "sha256:b27bfecede327a6d2da5fbc96bd859f114ecc398a6389d664f62085ee7ae6fc4"}, -] - -[package.extras] -dev = ["freezegun (>=0.2.8)", "mypy (>=1.4)", "pretend", "pytest (>=6.0)", "pytest-asyncio (>=0.17)", "rich", "simplejson", "twisted"] -docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-mermaid", "sphinxext-opengraph", "twisted"] -tests = ["freezegun (>=0.2.8)", "pretend", "pytest (>=6.0)", "pytest-asyncio (>=0.17)", "simplejson"] -typing = ["mypy (>=1.4)", "rich", "twisted"] - [[package]] name = "typing-extensions" version = "4.12.2" @@ -2388,4 +2370,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.1" python-versions = "^3.12" -content-hash = "6d652a19a90b9354a55401b6209965da718491a632975a1af19fbbdddb940ab2" +content-hash = "7aee9790de4b8de42ddd0f1d6827c8d476fce4426a848eb7235cecc9b7d5315f" diff --git a/pyproject.toml b/pyproject.toml index ff4df31..525d2a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ license = "EUPL-2.1" [tool.poetry.dependencies] python = "^3.12" plugfs = {git = "https://github.com/amsterdam/plugfs"} -structlog = "^24.1.0" [tool.poetry.group.dev.dependencies] anyio = "^4.6.2" diff --git a/tests/test_actions/test_melding_actions.py b/tests/test_actions/test_melding_actions.py index 7ac5251..3813a35 100644 --- a/tests/test_actions/test_melding_actions.py +++ b/tests/test_actions/test_melding_actions.py @@ -1,8 +1,9 @@ +import logging from datetime import datetime, timedelta from unittest.mock import AsyncMock, Mock import pytest -from structlog.testing import capture_logs +from _pytest.logging import LogCaptureFixture from meldingen_core.actions.melding import ( MeldingAddAttachmentsAction, @@ -45,7 +46,7 @@ async def test_melding_create_action() -> None: @pytest.mark.anyio -async def test_melding_create_action_with_classification_not_found() -> None: +async def test_melding_create_action_with_classification_not_found(caplog: LogCaptureFixture) -> None: classifier = AsyncMock(Classifier, side_effect=ClassificationNotFoundException) state_machine = Mock(BaseMeldingStateMachine) repository = Mock(BaseMeldingRepository) @@ -54,12 +55,13 @@ async def test_melding_create_action_with_classification_not_found() -> None: ) melding = Melding("text") - with capture_logs() as captured_logs: + with caplog.at_level(logging.ERROR): await action(melding) - assert len(captured_logs) == 1 - assert captured_logs[0].get("log_level") == "error" - assert captured_logs[0].get("event") == "Classifier failed to find classification!" + assert len(caplog.records) == 1 + assert caplog.records[0].levelname == "ERROR" + assert caplog.records[0].message == "Classifier failed to find classification!" + state_machine.transition.assert_not_awaited()