Skip to main content
Glama
test_logging.py2.66 kB
"""Unit tests for Logging configuration. Tests structured logging setup. """ from __future__ import annotations from unittest.mock import patch from sso_mcp_server import configure_logging, get_logger class TestConfigureLogging: """Tests for configure_logging function.""" def test_configure_logging_default_level(self) -> None: """Test configure_logging with default INFO level.""" configure_logging() # Should not raise def test_configure_logging_debug_level(self) -> None: """Test configure_logging with DEBUG level.""" configure_logging("DEBUG") # Should not raise def test_configure_logging_case_insensitive(self) -> None: """Test configure_logging handles case-insensitive levels.""" configure_logging("warning") configure_logging("WARNING") configure_logging("Warning") # All should work def test_configure_logging_tty_uses_console_renderer(self) -> None: """Test that TTY mode uses console renderer.""" with patch("sys.stderr") as mock_stderr: mock_stderr.isatty.return_value = True configure_logging() # Structlog is configured, check it doesn't raise def test_configure_logging_non_tty_uses_json_renderer(self) -> None: """Test that non-TTY mode uses JSON renderer.""" with patch("sys.stderr") as mock_stderr: mock_stderr.isatty.return_value = False configure_logging() # Structlog is configured, check it doesn't raise class TestGetLogger: """Tests for get_logger function.""" def test_get_logger_returns_bound_logger(self) -> None: """Test that get_logger returns a bound logger.""" configure_logging() # Ensure logging is configured logger = get_logger() assert logger is not None def test_get_logger_with_name(self) -> None: """Test that get_logger with name binds logger_name.""" configure_logging() logger = get_logger("test_module") # Logger should have the name bound assert logger is not None def test_get_logger_without_name(self) -> None: """Test that get_logger without name still works.""" configure_logging() logger = get_logger(None) assert logger is not None def test_get_logger_can_log(self) -> None: """Test that returned logger can actually log.""" configure_logging() logger = get_logger("test") # Should not raise logger.info("test_message", key="value") logger.debug("debug_message") logger.warning("warning_message")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DauQuangThanh/sso-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server