|
| 1 | +import logging |
| 2 | +import pytest |
| 3 | +from armctl import Logger |
| 4 | +from armctl.templates import logger as logger_module |
| 5 | + |
| 6 | + |
| 7 | +def test_send_level_name(): |
| 8 | + assert logging.getLevelName(logger_module.SEND_LEVEL) == "SEND" |
| 9 | + |
| 10 | + |
| 11 | +def test_receive_level_name(): |
| 12 | + assert logging.getLevelName(logger_module.RECEIVE_LEVEL) == "RECV" |
| 13 | + |
| 14 | + |
| 15 | +def test_logger_send_and_receive_methods_exist(): |
| 16 | + log = logging.getLogger("test_logger") |
| 17 | + assert hasattr(log, "send") |
| 18 | + assert hasattr(log, "receive") |
| 19 | + |
| 20 | + |
| 21 | +def test_logger_send_logs_message(caplog): |
| 22 | + log = logging.getLogger("test_logger_send") |
| 23 | + with caplog.at_level(logger_module.SEND_LEVEL): |
| 24 | + log.send("This is a SEND message") |
| 25 | + assert any("This is a SEND message" in m for m in caplog.messages) |
| 26 | + assert any(r.levelname == "SEND" for r in caplog.records) |
| 27 | + |
| 28 | + |
| 29 | +def test_logger_receive_logs_message(caplog): |
| 30 | + log = logging.getLogger("test_logger_receive") |
| 31 | + with caplog.at_level(logger_module.RECEIVE_LEVEL): |
| 32 | + log.receive("This is a RECV message") |
| 33 | + assert any("This is a RECV message" in m for m in caplog.messages) |
| 34 | + assert any(r.levelname == "RECV" for r in caplog.records) |
| 35 | + |
| 36 | + |
| 37 | +def test_logger_verbosity_and_enable_disable(caplog): |
| 38 | + with caplog.at_level(logging.INFO): |
| 39 | + Logger.enable() # Make sure logging is enabled |
| 40 | + logging.info("This should appear") |
| 41 | + assert "This should appear" in caplog.text |
| 42 | + Logger.disable() |
| 43 | + logging.info("This should NOT appear") |
| 44 | + assert "This should NOT appear" not in caplog.text |
| 45 | + Logger.enable() # Re-enable for other tests |
0 commit comments