adds logging tests and type hints

This commit is contained in:
Mose Müller 2025-02-28 16:56:32 +01:00
parent bd33252775
commit c8979ab2e6

View File

@ -1,9 +1,10 @@
import logging import logging
from pytest import LogCaptureFixture import pytest
from pydase.utils.logging import configure_root_logger_with_pydase_formatter
def test_log_error(caplog: LogCaptureFixture): def test_log_error(caplog: pytest.LogCaptureFixture) -> None:
logger = logging.getLogger("pydase") logger = logging.getLogger("pydase")
logger.setLevel(logging.ERROR) logger.setLevel(logging.ERROR)
@ -20,7 +21,7 @@ def test_log_error(caplog: LogCaptureFixture):
assert any(record.levelname == "ERROR" for record in caplog.records) assert any(record.levelname == "ERROR" for record in caplog.records)
def test_log_warning(caplog: LogCaptureFixture): def test_log_warning(caplog: pytest.LogCaptureFixture) -> None:
logger = logging.getLogger("pydase") logger = logging.getLogger("pydase")
logger.setLevel(logging.WARNING) logger.setLevel(logging.WARNING)
@ -37,7 +38,7 @@ def test_log_warning(caplog: LogCaptureFixture):
assert any(record.levelname == "ERROR" for record in caplog.records) assert any(record.levelname == "ERROR" for record in caplog.records)
def test_log_debug(caplog: LogCaptureFixture): def test_log_debug(caplog: pytest.LogCaptureFixture) -> None:
logger = logging.getLogger("pydase") logger = logging.getLogger("pydase")
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -53,7 +54,7 @@ def test_log_debug(caplog: LogCaptureFixture):
assert "This is an error message" in caplog.text assert "This is an error message" in caplog.text
def test_log_info(caplog: LogCaptureFixture): def test_log_info(caplog: pytest.LogCaptureFixture) -> None:
logger = logging.getLogger("pydase") logger = logging.getLogger("pydase")
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
@ -67,3 +68,21 @@ def test_log_info(caplog: LogCaptureFixture):
assert "This is an info message" in caplog.text assert "This is an info message" in caplog.text
assert "This is a warning message" in caplog.text assert "This is a warning message" in caplog.text
assert "This is an error message" in caplog.text assert "This is an error message" in caplog.text
def test_before_configuring_root_logger(caplog: pytest.LogCaptureFixture) -> None:
logger = logging.getLogger(__name__)
logger.info("Hello world")
assert "Hello world" not in caplog.text
def test_configure_root_logger(caplog: pytest.LogCaptureFixture) -> None:
configure_root_logger_with_pydase_formatter()
logger = logging.getLogger(__name__)
logger.info("Hello world")
assert (
"INFO tests.utils.test_logging:test_logging.py:83 Hello world"
in caplog.text
)