mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add compatibility tests for DhcpServiceInfo (#60752)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
fc3c9b1b4e
commit
7f355681a7
@ -843,3 +843,34 @@ async def test_aiodiscover_finds_new_hosts_after_interval(hass):
|
||||
hostname="connect",
|
||||
macaddress="b8b7f16db533",
|
||||
)
|
||||
|
||||
|
||||
async def test_service_info_compatibility(hass, caplog):
|
||||
"""Test compatibility with old-style dict.
|
||||
|
||||
To be removed in 2022.6
|
||||
"""
|
||||
discovery_info = dhcp.DhcpServiceInfo(
|
||||
ip="192.168.210.56",
|
||||
hostname="connect",
|
||||
macaddress="b8b7f16db533",
|
||||
)
|
||||
|
||||
# Ensure first call get logged
|
||||
assert discovery_info["ip"] == "192.168.210.56"
|
||||
assert discovery_info.get("ip") == "192.168.210.56"
|
||||
assert discovery_info.get("ip", "fallback_host") == "192.168.210.56"
|
||||
assert discovery_info.get("invalid_key", "fallback_host") == "fallback_host"
|
||||
assert "Detected code that accessed discovery_info['ip']" in caplog.text
|
||||
assert "Detected code that accessed discovery_info.get('ip')" not in caplog.text
|
||||
|
||||
# Ensure second call doesn't get logged
|
||||
caplog.clear()
|
||||
assert discovery_info["ip"] == "192.168.210.56"
|
||||
assert discovery_info.get("ip") == "192.168.210.56"
|
||||
assert "Detected code that accessed discovery_info['ip']" not in caplog.text
|
||||
assert "Detected code that accessed discovery_info.get('ip')" not in caplog.text
|
||||
|
||||
discovery_info._warning_logged = False # pylint: disable=[protected-access]
|
||||
assert discovery_info.get("ip") == "192.168.210.56"
|
||||
assert "Detected code that accessed discovery_info.get('ip')" in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user