Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""Unit tests for logger.py."""

from unittest.mock import patch
from zeroconf.logger import QuietLogger


def test_log_warning_once():
"""Test we only log with warning level once."""
quiet_logger = QuietLogger()
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
"zeroconf.logger.log.debug"
) as mock_log_debug:
quiet_logger.log_warning_once("the warning")

assert mock_log_warning.mock_calls
assert not mock_log_debug.mock_calls

with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
"zeroconf.logger.log.debug"
) as mock_log_debug:
quiet_logger.log_warning_once("the warning")

assert not mock_log_warning.mock_calls
assert mock_log_debug.mock_calls


def test_log_exception_warning():
"""Test we only log with warning level once."""
quiet_logger = QuietLogger()
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
"zeroconf.logger.log.debug"
) as mock_log_debug:
quiet_logger.log_exception_warning("the exception warning")

assert mock_log_warning.mock_calls
assert not mock_log_debug.mock_calls

with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
"zeroconf.logger.log.debug"
) as mock_log_debug:
quiet_logger.log_exception_warning("the exception warning")

assert not mock_log_warning.mock_calls
assert mock_log_debug.mock_calls