mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-03 20:30:40 +02:00
add logging tests
This commit is contained in:
parent
c6a96ba6c0
commit
7b04298ead
71
tests/utils/test_logging.py
Normal file
71
tests/utils/test_logging.py
Normal file
@ -0,0 +1,71 @@
|
||||
import logging
|
||||
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from pydase.utils.logging import setup_logging
|
||||
|
||||
|
||||
def test_log_error(caplog: LogCaptureFixture):
|
||||
setup_logging("ERROR")
|
||||
logger = logging.getLogger()
|
||||
logger.debug("This is a debug message")
|
||||
logger.info("This is an info message")
|
||||
logger.warning("This is a warning message")
|
||||
logger.error("This is an error message")
|
||||
|
||||
# Check the log records as well as the level.
|
||||
assert "This is a debug message" not in caplog.text
|
||||
assert "This is an info message" not in caplog.text
|
||||
assert "This is a warning message" not in caplog.text
|
||||
assert "This is an error message" in caplog.text
|
||||
assert any(record.levelname == "ERROR" for record in caplog.records)
|
||||
|
||||
|
||||
def test_log_warning(caplog: LogCaptureFixture):
|
||||
setup_logging("WARNING")
|
||||
logger = logging.getLogger()
|
||||
logger.debug("This is a debug message")
|
||||
logger.info("This is an info message")
|
||||
logger.warning("This is a warning message")
|
||||
logger.error("This is an error message")
|
||||
|
||||
# Check the log records as well as the level.
|
||||
assert "This is a debug message" not in caplog.text
|
||||
assert "This is an info message" not in caplog.text
|
||||
assert "This is a warning message" in caplog.text
|
||||
assert "This is an error message" in caplog.text
|
||||
assert any(record.levelname == "ERROR" for record in caplog.records)
|
||||
|
||||
|
||||
def test_log_debug(caplog: LogCaptureFixture):
|
||||
setup_logging("DEBUG")
|
||||
logger = (
|
||||
logging.getLogger()
|
||||
) # Get the root logger or replace with the appropriate logger.
|
||||
logger.debug("This is a debug message")
|
||||
logger.info("This is an info message")
|
||||
logger.warning("This is a warning message")
|
||||
logger.error("This is an error message")
|
||||
|
||||
# Now, check that the message is in the log records.
|
||||
assert "This is a debug 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 an error message" in caplog.text
|
||||
|
||||
|
||||
def test_log_info(caplog: LogCaptureFixture):
|
||||
setup_logging("INFO")
|
||||
logger = (
|
||||
logging.getLogger()
|
||||
) # Get the root logger or replace with the appropriate logger.
|
||||
logger.debug("This is a debug message")
|
||||
logger.info("This is an info message")
|
||||
logger.warning("This is a warning message")
|
||||
logger.error("This is an error message")
|
||||
|
||||
# Now, check that the message is in the log records.
|
||||
assert "This is a debug message" not in caplog.text
|
||||
assert "This is an info message" in caplog.text
|
||||
assert "This is a warning message" in caplog.text
|
||||
assert "This is an error message" in caplog.text
|
Loading…
x
Reference in New Issue
Block a user