mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix aprs tests with python 3.11 (#88189)
* Fix aprs tests with python 3.11 * hints
This commit is contained in:
parent
80e2f96097
commit
c8b827b46b
@ -1,7 +1,9 @@
|
||||
"""Test APRS device tracker."""
|
||||
from unittest.mock import Mock, patch
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import aprslib
|
||||
from aprslib import IS
|
||||
import pytest
|
||||
|
||||
import homeassistant.components.aprs.device_tracker as device_tracker
|
||||
@ -16,6 +18,13 @@ TEST_HOST = "testhost"
|
||||
TEST_PASSWORD = "testpass"
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_ais")
|
||||
def mock_ais() -> Generator[MagicMock, None, None]:
|
||||
"""Mock aprslib."""
|
||||
with patch("aprslib.IS") as mock_ais:
|
||||
yield mock_ais
|
||||
|
||||
|
||||
def test_make_filter() -> None:
|
||||
"""Test filter."""
|
||||
callsigns = ["CALLSIGN1", "callsign2"]
|
||||
@ -86,9 +95,8 @@ def test_gps_accuracy_invalid_float() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def test_aprs_listener() -> None:
|
||||
def test_aprs_listener(mock_ais: MagicMock) -> None:
|
||||
"""Test listener thread."""
|
||||
with patch("aprslib.IS") as mock_ais:
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -113,8 +121,8 @@ def test_aprs_listener() -> None:
|
||||
|
||||
def test_aprs_listener_start_fail() -> None:
|
||||
"""Test listener thread start failure."""
|
||||
with patch(
|
||||
"aprslib.IS.connect", side_effect=aprslib.ConnectionError("Unable to connect.")
|
||||
with patch.object(
|
||||
IS, "connect", side_effect=aprslib.ConnectionError("Unable to connect.")
|
||||
):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
@ -136,9 +144,8 @@ def test_aprs_listener_start_fail() -> None:
|
||||
assert listener.start_message == "Unable to connect."
|
||||
|
||||
|
||||
def test_aprs_listener_stop() -> None:
|
||||
def test_aprs_listener_stop(mock_ais: MagicMock) -> None:
|
||||
"""Test listener thread stop."""
|
||||
with patch("aprslib.IS"):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -162,9 +169,8 @@ def test_aprs_listener_stop() -> None:
|
||||
listener.ais.close.assert_called_with()
|
||||
|
||||
|
||||
def test_aprs_listener_rx_msg() -> None:
|
||||
def test_aprs_listener_rx_msg(mock_ais: MagicMock) -> None:
|
||||
"""Test rx_msg."""
|
||||
with patch("aprslib.IS"):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -199,9 +205,8 @@ def test_aprs_listener_rx_msg() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_aprs_listener_rx_msg_ambiguity() -> None:
|
||||
def test_aprs_listener_rx_msg_ambiguity(mock_ais: MagicMock) -> None:
|
||||
"""Test rx_msg with posambiguity."""
|
||||
with patch("aprslib.IS"):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -236,9 +241,8 @@ def test_aprs_listener_rx_msg_ambiguity() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_aprs_listener_rx_msg_ambiguity_invalid() -> None:
|
||||
def test_aprs_listener_rx_msg_ambiguity_invalid(mock_ais: MagicMock) -> None:
|
||||
"""Test rx_msg with invalid posambiguity."""
|
||||
with patch("aprslib.IS"):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -271,9 +275,8 @@ def test_aprs_listener_rx_msg_ambiguity_invalid() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_aprs_listener_rx_msg_no_position() -> None:
|
||||
def test_aprs_listener_rx_msg_no_position(mock_ais: MagicMock) -> None:
|
||||
"""Test rx_msg with non-position report."""
|
||||
with patch("aprslib.IS"):
|
||||
callsign = TEST_CALLSIGN
|
||||
password = TEST_PASSWORD
|
||||
host = TEST_HOST
|
||||
@ -324,7 +327,7 @@ async def test_setup_scanner(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_setup_scanner_timeout(hass: HomeAssistant) -> None:
|
||||
"""Test setup_scanner failure from timeout."""
|
||||
with patch("aprslib.IS.connect", side_effect=TimeoutError):
|
||||
with patch.object(IS, "connect", side_effect=TimeoutError):
|
||||
config = {
|
||||
"username": TEST_CALLSIGN,
|
||||
"password": TEST_PASSWORD,
|
||||
|
Loading…
x
Reference in New Issue
Block a user