Skip to content

Commit f34f9c4

Browse files
committed
Mark zeroconf.logger as protected by renaming to zeroconf._logger
- The public API should only access zeroconf and zeroconf.aio as internals may be relocated between releases
1 parent 1a2ee68 commit f34f9c4

9 files changed

Lines changed: 17 additions & 17 deletions

File tree

tests/test_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
136136
# mock zeroconf's logger warning() and debug()
137137
from unittest.mock import patch
138138

139-
patch_warn = patch('zeroconf.log.warning')
140-
patch_debug = patch('zeroconf.log.debug')
139+
patch_warn = patch('zeroconf._logger.log.warning')
140+
patch_debug = patch('zeroconf._logger.log.debug')
141141
mocked_log_warn = patch_warn.start()
142142
mocked_log_debug = patch_debug.start()
143143

tests/test_logger.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
"""Unit tests for logger.py."""
66

77
from unittest.mock import patch
8-
from zeroconf.logger import QuietLogger
8+
from zeroconf._logger import QuietLogger
99

1010

1111
def test_log_warning_once():
1212
"""Test we only log with warning level once."""
1313
quiet_logger = QuietLogger()
14-
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
15-
"zeroconf.logger.log.debug"
14+
with patch("zeroconf._logger.log.warning") as mock_log_warning, patch(
15+
"zeroconf._logger.log.debug"
1616
) as mock_log_debug:
1717
quiet_logger.log_warning_once("the warning")
1818

1919
assert mock_log_warning.mock_calls
2020
assert not mock_log_debug.mock_calls
2121

22-
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
23-
"zeroconf.logger.log.debug"
22+
with patch("zeroconf._logger.log.warning") as mock_log_warning, patch(
23+
"zeroconf._logger.log.debug"
2424
) as mock_log_debug:
2525
quiet_logger.log_warning_once("the warning")
2626

@@ -31,16 +31,16 @@ def test_log_warning_once():
3131
def test_log_exception_warning():
3232
"""Test we only log with warning level once."""
3333
quiet_logger = QuietLogger()
34-
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
35-
"zeroconf.logger.log.debug"
34+
with patch("zeroconf._logger.log.warning") as mock_log_warning, patch(
35+
"zeroconf._logger.log.debug"
3636
) as mock_log_debug:
3737
quiet_logger.log_exception_warning("the exception warning")
3838

3939
assert mock_log_warning.mock_calls
4040
assert not mock_log_debug.mock_calls
4141

42-
with patch("zeroconf.logger.log.warning") as mock_log_warning, patch(
43-
"zeroconf.logger.log.debug"
42+
with patch("zeroconf._logger.log.warning") as mock_log_warning, patch(
43+
"zeroconf._logger.log.debug"
4444
) as mock_log_debug:
4545
quiet_logger.log_exception_warning("the exception warning")
4646

zeroconf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DNSService,
3737
DNSText,
3838
)
39+
from ._logger import QuietLogger, log # noqa # import needed for backwards compat
3940
from .exceptions import ( # noqa # import needed for backwards compat
4041
AbstractMethodException,
4142
BadTypeInNameException,
@@ -45,7 +46,6 @@
4546
NonUniqueNameException,
4647
ServiceNameAlreadyRegistered,
4748
)
48-
from .logger import QuietLogger, log # noqa # import needed for backwards compat
4949
from .services import ( # noqa # import needed for backwards compat
5050
instance_name_from_service_info,
5151
Signal,

zeroconf/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from ._dns import DNSIncoming, DNSOutgoing, DNSQuestion
3232
from ._handlers import QueryHandler, RecordManager
33+
from ._logger import QuietLogger, log
3334
from .cache import DNSCache
3435
from .const import (
3536
_CACHE_CLEANUP_INTERVAL,
@@ -48,7 +49,6 @@
4849
_UNREGISTER_TIME,
4950
)
5051
from .exceptions import NonUniqueNameException
51-
from .logger import QuietLogger, log
5252
from .services import (
5353
RecordUpdateListener,
5454
ServiceBrowser,

zeroconf/_dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import struct
2626
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Union, cast
2727

28+
from ._logger import QuietLogger, log
2829
from .const import (
2930
_CLASSES,
3031
_CLASS_MASK,
@@ -48,7 +49,6 @@
4849
_TYPE_TXT,
4950
)
5051
from .exceptions import AbstractMethodException, IncomingDecodeError, NamePartTooLongException
51-
from .logger import QuietLogger, log
5252
from .utils.net import _is_v6_address
5353
from .utils.struct import int2byte
5454
from .utils.time import current_time_millis, millis_to_seconds

zeroconf/_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import List, Optional, TYPE_CHECKING, Union
2525

2626
from ._dns import DNSAddress, DNSIncoming, DNSOutgoing, DNSPointer, DNSQuestion, DNSRecord
27+
from ._logger import log
2728
from .const import (
2829
_CLASS_IN,
2930
_DNS_OTHER_TTL,
@@ -36,7 +37,6 @@
3637
_TYPE_SRV,
3738
_TYPE_TXT,
3839
)
39-
from .logger import log
4040
from .services import (
4141
RecordUpdateListener,
4242
)
File renamed without changes.

zeroconf/asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
USA
2121
"""
2222

23+
from ._logger import log
2324
from .aio import AsyncZeroconf # pylint: disable=unused-import # noqa
24-
from .logger import log
2525

2626
# The asyncio module would shadow system asyncio in some import cases
2727
# to resolve this, the module has been renamed zeroconf.aio

zeroconf/utils/net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
import ifaddr
3232

33+
from .._logger import log
3334
from ..const import _IPPROTO_IPV6, _MDNS_ADDR6_BYTES, _MDNS_ADDR_BYTES, _MDNS_PORT
34-
from ..logger import log
3535

3636

3737
@enum.unique

0 commit comments

Comments
 (0)