Skip to content

Commit

Permalink
Add compatibility tests for DhcpServiceInfo (home-assistant#60752)
Browse files Browse the repository at this point in the history
Co-authored-by: epenet <epenet@users.noreply.github.com>
  • Loading branch information
2 people authored and pull[bot] committed Jun 30, 2023
1 parent be2d08b commit 1753412
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/components/dhcp/test_init.py
Expand Up @@ -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

0 comments on commit 1753412

Please sign in to comment.