Skip to content

Commit ff5f7a9

Browse files
committed
Add missing coverage for QuietLogger
1 parent e2e4eed commit ff5f7a9

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_logger.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
"""Unit tests for logger.py."""
6+
7+
from unittest.mock import patch
8+
from zeroconf.logger import QuietLogger
9+
10+
11+
def test_log_warning_once():
12+
"""Test we only log with warning level once."""
13+
quiet_logger = QuietLogger()
14+
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
15+
"zeroconf.logger.log.debug"
16+
) as mock_log_debug:
17+
quiet_logger.log_warning_once("the warning")
18+
19+
assert mock_log_warning.mock_calls
20+
assert not mock_log_debug.mock_calls
21+
22+
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
23+
"zeroconf.logger.log.debug"
24+
) as mock_log_debug:
25+
quiet_logger.log_warning_once("the warning")
26+
27+
assert not mock_log_warning.mock_calls
28+
assert mock_log_debug.mock_calls
29+
30+
31+
def test_log_exception_warning():
32+
"""Test we only log with warning level once."""
33+
quiet_logger = QuietLogger()
34+
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
35+
"zeroconf.logger.log.debug"
36+
) as mock_log_debug:
37+
quiet_logger.log_exception_warning("the exception warning")
38+
39+
assert mock_log_warning.mock_calls
40+
assert not mock_log_debug.mock_calls
41+
42+
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
43+
"zeroconf.logger.log.debug"
44+
) as mock_log_debug:
45+
quiet_logger.log_exception_warning("the exception warning")
46+
47+
assert not mock_log_warning.mock_calls
48+
assert mock_log_debug.mock_calls

0 commit comments

Comments
 (0)