Fix slow aestransport and cli tests (#816)

This commit is contained in:
Steven B
2024-03-11 10:17:12 +00:00
committed by GitHub
parent 3495bd83df
commit 7507837734
5 changed files with 16 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import warnings
from typing import Dict
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
import pytest
@@ -48,8 +48,8 @@ def dummy_protocol():
transport = DummyTransport(config=DeviceConfig(host="127.0.0.123"))
protocol = SmartProtocol(transport=transport)
return protocol
with patch.object(protocol, "BACKOFF_SECONDS_AFTER_TIMEOUT", 0):
yield protocol
def pytest_configure():

View File

@@ -148,4 +148,5 @@ def filter_fixtures(
print(f"# {desc}")
for value in filtered:
print(f"\t{value.name}")
filtered.sort()
return filtered

View File

@@ -135,6 +135,7 @@ async def test_login_errors(mocker, inner_error_codes, expectation, call_count):
transport._state = TransportState.LOGIN_REQUIRED
transport._session_expire_at = time.time() + 86400
transport._encryption_session = mock_aes_device.encryption_session
mocker.patch.object(transport, "BACKOFF_SECONDS_AFTER_LOGIN_ERROR", 0)
assert transport._token_url is None

View File

@@ -149,10 +149,15 @@ async def test_command_with_child(dev, mocker):
runner = CliRunner()
update_mock = mocker.patch.object(dev, "update")
dummy_child = mocker.create_autospec(IotDevice)
query_mock = mocker.patch.object(
dummy_child, "_query_helper", return_value={"dummy": "response"}
)
# create_autospec for device slows tests way too much, so we use a dummy here
class DummyDevice(dev.__class__):
def __init__(self):
super().__init__("127.0.0.1")
async def _query_helper(*_, **__):
return {"dummy": "response"}
dummy_child = DummyDevice()
mocker.patch.object(dev, "_children", {"XYZ": dummy_child})
mocker.patch.object(dev, "get_child_device", return_value=dummy_child)
@@ -165,7 +170,6 @@ async def test_command_with_child(dev, mocker):
)
update_mock.assert_called()
query_mock.assert_called()
assert '{"dummy": "response"}' in res.output
assert res.exit_code == 0