mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
parent
8c993116e1
commit
ef800335fb
@ -141,4 +141,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pyairvisual):
|
|||||||
"""Define a fixture to set up airvisual."""
|
"""Define a fixture to set up airvisual."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -40,4 +40,4 @@ def fixture_mock_aladdinconnect_api():
|
|||||||
mock_opener.open_door = AsyncMock(return_value=True)
|
mock_opener.open_door = AsyncMock(return_value=True)
|
||||||
mock_opener.close_door = AsyncMock(return_value=True)
|
mock_opener.close_door = AsyncMock(return_value=True)
|
||||||
|
|
||||||
yield mock_opener
|
return mock_opener
|
||||||
|
@ -60,4 +60,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aioambient):
|
|||||||
"""Define a fixture to set up ambient_station."""
|
"""Define a fixture to set up ambient_station."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -92,7 +92,7 @@ def full_device(mock_scan, dmap_pin):
|
|||||||
airplay_service(),
|
airplay_service(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -112,7 +112,7 @@ def mrp_device(mock_scan):
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -132,7 +132,7 @@ def airplay_with_disabled_mrp(mock_scan):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -152,7 +152,7 @@ def dmap_device(mock_scan):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -172,7 +172,7 @@ def dmap_device_with_credentials(mock_scan):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -187,7 +187,7 @@ def airplay_device_with_password(mock_scan):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -206,4 +206,4 @@ def dmap_with_requirement(mock_scan, pairing_requirement):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield mock_scan
|
return mock_scan
|
||||||
|
@ -154,7 +154,7 @@ def default_request_fixture(respx_mock):
|
|||||||
)
|
)
|
||||||
respx.post(f"{path}/local/vmd/control.cgi").respond(json=VMD4_RESPONSE)
|
respx.post(f"{path}/local/vmd/control.cgi").respond(json=VMD4_RESPONSE)
|
||||||
|
|
||||||
yield __mock_default_requests
|
return __mock_default_requests
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -187,7 +187,7 @@ async def prep_config_entry_fixture(hass, config_entry, setup_default_vapix_requ
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
return config_entry
|
return config_entry
|
||||||
|
|
||||||
yield __mock_setup_config_entry
|
return __mock_setup_config_entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_config_entry")
|
@pytest.fixture(name="setup_config_entry")
|
||||||
@ -195,7 +195,7 @@ async def setup_config_entry_fixture(hass, config_entry, setup_default_vapix_req
|
|||||||
"""Define a fixture to set up Axis network device."""
|
"""Define a fixture to set up Axis network device."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield config_entry
|
return config_entry
|
||||||
|
|
||||||
|
|
||||||
# RTSP fixtures
|
# RTSP fixtures
|
||||||
@ -283,7 +283,7 @@ def mock_rtsp_event(mock_axis_rtspclient):
|
|||||||
|
|
||||||
mock_axis_rtspclient(data=event.encode("utf-8"))
|
mock_axis_rtspclient(data=event.encode("utf-8"))
|
||||||
|
|
||||||
yield send_event
|
return send_event
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -295,4 +295,4 @@ def mock_rtsp_signal_state(mock_axis_rtspclient):
|
|||||||
signal = Signal.PLAYING if connected else Signal.FAILED
|
signal = Signal.PLAYING if connected else Signal.FAILED
|
||||||
mock_axis_rtspclient(state=signal)
|
mock_axis_rtspclient(state=signal)
|
||||||
|
|
||||||
yield send_signal
|
return send_signal
|
||||||
|
@ -84,7 +84,7 @@ def product_class_mock_fixture():
|
|||||||
"""Return a mocked feature."""
|
"""Return a mocked feature."""
|
||||||
path = "homeassistant.components.blebox.config_flow.Box"
|
path = "homeassistant.components.blebox.config_flow.Box"
|
||||||
patcher = patch(path, DEFAULT, blebox_uniapi.box.Box, True, True)
|
patcher = patch(path, DEFAULT, blebox_uniapi.box.Box, True, True)
|
||||||
yield patcher
|
return patcher
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_with_connection_failure(hass, product_class_mock):
|
async def test_flow_with_connection_failure(hass, product_class_mock):
|
||||||
|
@ -11,7 +11,7 @@ from tests.common import ANY, mock_area_registry
|
|||||||
def client(hass, hass_ws_client):
|
def client(hass, hass_ws_client):
|
||||||
"""Fixture that can interact with the config manager API."""
|
"""Fixture that can interact with the config manager API."""
|
||||||
hass.loop.run_until_complete(area_registry.async_setup(hass))
|
hass.loop.run_until_complete(area_registry.async_setup(hass))
|
||||||
yield hass.loop.run_until_complete(hass_ws_client(hass))
|
return hass.loop.run_until_complete(hass_ws_client(hass))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -18,7 +18,7 @@ from tests.components.blueprint.conftest import stub_blueprint_populate # noqa:
|
|||||||
def client(hass, hass_ws_client):
|
def client(hass, hass_ws_client):
|
||||||
"""Fixture that can interact with the config manager API."""
|
"""Fixture that can interact with the config manager API."""
|
||||||
hass.loop.run_until_complete(device_registry.async_setup(hass))
|
hass.loop.run_until_complete(device_registry.async_setup(hass))
|
||||||
yield hass.loop.run_until_complete(hass_ws_client(hass))
|
return hass.loop.run_until_complete(hass_ws_client(hass))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -26,7 +26,7 @@ from tests.common import (
|
|||||||
def client(hass, hass_ws_client):
|
def client(hass, hass_ws_client):
|
||||||
"""Fixture that can interact with the config manager API."""
|
"""Fixture that can interact with the config manager API."""
|
||||||
hass.loop.run_until_complete(entity_registry.async_setup(hass))
|
hass.loop.run_until_complete(entity_registry.async_setup(hass))
|
||||||
yield hass.loop.run_until_complete(hass_ws_client(hass))
|
return hass.loop.run_until_complete(hass_ws_client(hass))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -57,7 +57,7 @@ async def setup_integration(recorder_mock):
|
|||||||
@freeze_time("2022-04-19 07:53:05")
|
@freeze_time("2022-04-19 07:53:05")
|
||||||
def frozen_time():
|
def frozen_time():
|
||||||
"""Freeze clock for tests."""
|
"""Freeze clock for tests."""
|
||||||
yield
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_statistics_for_entity(statistics_results, entity_id):
|
def get_statistics_for_entity(statistics_results, entity_id):
|
||||||
|
@ -18,7 +18,7 @@ def fakeimgbytes_png():
|
|||||||
"""Fake image in RAM for testing."""
|
"""Fake image in RAM for testing."""
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
Image.new("RGB", (1, 1)).save(buf, format="PNG")
|
Image.new("RGB", (1, 1)).save(buf, format="PNG")
|
||||||
yield bytes(buf.getbuffer())
|
return bytes(buf.getbuffer())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="package")
|
@pytest.fixture(scope="package")
|
||||||
@ -26,13 +26,13 @@ def fakeimgbytes_jpg():
|
|||||||
"""Fake image in RAM for testing."""
|
"""Fake image in RAM for testing."""
|
||||||
buf = BytesIO() # fake image in ram for testing.
|
buf = BytesIO() # fake image in ram for testing.
|
||||||
Image.new("RGB", (1, 1)).save(buf, format="jpeg")
|
Image.new("RGB", (1, 1)).save(buf, format="jpeg")
|
||||||
yield bytes(buf.getbuffer())
|
return bytes(buf.getbuffer())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="package")
|
@pytest.fixture(scope="package")
|
||||||
def fakeimgbytes_svg():
|
def fakeimgbytes_svg():
|
||||||
"""Fake image in RAM for testing."""
|
"""Fake image in RAM for testing."""
|
||||||
yield bytes(
|
return bytes(
|
||||||
'<svg xmlns="http://www.w3.org/2000/svg"><circle r="50"/></svg>',
|
'<svg xmlns="http://www.w3.org/2000/svg"><circle r="50"/></svg>',
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
@ -43,7 +43,7 @@ def fakeimgbytes_gif():
|
|||||||
"""Fake image in RAM for testing."""
|
"""Fake image in RAM for testing."""
|
||||||
buf = BytesIO() # fake image in ram for testing.
|
buf = BytesIO() # fake image in ram for testing.
|
||||||
Image.new("RGB", (1, 1)).save(buf, format="gif")
|
Image.new("RGB", (1, 1)).save(buf, format="gif")
|
||||||
yield bytes(buf.getbuffer())
|
return bytes(buf.getbuffer())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""PyTest fixtures and test helpers."""
|
"""PyTest fixtures and test helpers."""
|
||||||
from collections.abc import Awaitable, Callable, Generator
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
import time
|
import time
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from google.oauth2.credentials import Credentials
|
from google.oauth2.credentials import Credentials
|
||||||
import pytest
|
import pytest
|
||||||
@ -65,7 +66,7 @@ def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry:
|
|||||||
@pytest.fixture(name="setup_integration")
|
@pytest.fixture(name="setup_integration")
|
||||||
async def mock_setup_integration(
|
async def mock_setup_integration(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> Generator[ComponentSetup, None, None]:
|
) -> Callable[[], Coroutine[Any, Any, None]]:
|
||||||
"""Fixture for setting up the component."""
|
"""Fixture for setting up the component."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ async def mock_setup_integration(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
yield func
|
return func
|
||||||
|
|
||||||
|
|
||||||
class ExpectedCredentials:
|
class ExpectedCredentials:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Configure tests for the Google Mail integration."""
|
"""Configure tests for the Google Mail integration."""
|
||||||
from collections.abc import Awaitable, Callable, Generator
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
import time
|
import time
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from httplib2 import Response
|
from httplib2 import Response
|
||||||
@ -93,7 +94,7 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None:
|
|||||||
@pytest.fixture(name="setup_integration")
|
@pytest.fixture(name="setup_integration")
|
||||||
async def mock_setup_integration(
|
async def mock_setup_integration(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> Generator[ComponentSetup, None, None]:
|
) -> Callable[[], Coroutine[Any, Any, None]]:
|
||||||
"""Fixture for setting up the component."""
|
"""Fixture for setting up the component."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -116,4 +117,4 @@ async def mock_setup_integration(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
yield func
|
return func
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
"""Tests for Google Sheets."""
|
"""Tests for Google Sheets."""
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable, Generator
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
import http
|
import http
|
||||||
import time
|
import time
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -58,7 +59,7 @@ def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry:
|
|||||||
@pytest.fixture(name="setup_integration")
|
@pytest.fixture(name="setup_integration")
|
||||||
async def mock_setup_integration(
|
async def mock_setup_integration(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> Generator[ComponentSetup, None, None]:
|
) -> Callable[[], Coroutine[Any, Any, None]]:
|
||||||
"""Fixture for setting up the component."""
|
"""Fixture for setting up the component."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ async def mock_setup_integration(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
yield func
|
return func
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_success(
|
async def test_setup_success(
|
||||||
|
@ -21,7 +21,7 @@ async def mock_config_fixture(hass, data, options):
|
|||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield config_entry
|
return config_entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="bypass_setup")
|
@pytest.fixture(name="bypass_setup")
|
||||||
|
@ -69,14 +69,14 @@ def mock_update_duration_fixture(mock_update):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
yield mock_update
|
return mock_update
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_update_empty")
|
@pytest.fixture(name="mock_update_empty")
|
||||||
def mock_update_empty_fixture(mock_update):
|
def mock_update_empty_fixture(mock_update):
|
||||||
"""Mock an update to the sensor with an empty response."""
|
"""Mock an update to the sensor with an empty response."""
|
||||||
mock_update.return_value = None
|
mock_update.return_value = None
|
||||||
yield mock_update
|
return mock_update
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -27,4 +27,4 @@ def hass_history(hass_recorder):
|
|||||||
)
|
)
|
||||||
assert setup_component(hass, history.DOMAIN, config)
|
assert setup_component(hass, history.DOMAIN, config)
|
||||||
|
|
||||||
yield hass
|
return hass
|
||||||
|
@ -14,7 +14,7 @@ def mock_disco():
|
|||||||
disco = Mock()
|
disco = Mock()
|
||||||
disco.pi_disco = Mock()
|
disco.pi_disco = Mock()
|
||||||
disco.pi_disco.controllers = {}
|
disco.pi_disco.controllers = {}
|
||||||
yield disco
|
return disco
|
||||||
|
|
||||||
|
|
||||||
def _mock_start_discovery(hass, mock_disco):
|
def _mock_start_discovery(hass, mock_disco):
|
||||||
|
@ -32,7 +32,7 @@ def meraki_client(event_loop, hass, hass_client):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
yield loop.run_until_complete(hass_client())
|
return loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client):
|
async def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client):
|
||||||
|
@ -59,11 +59,11 @@ def mock_reload_entry() -> Generator[AsyncMock, None, None]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_mjpeg_requests(requests_mock: Mocker) -> Generator[Mocker, None, None]:
|
def mock_mjpeg_requests(requests_mock: Mocker) -> Mocker:
|
||||||
"""Fixture to provide a requests mocker."""
|
"""Fixture to provide a requests mocker."""
|
||||||
requests_mock.get("https://example.com/mjpeg", text="resp")
|
requests_mock.get("https://example.com/mjpeg", text="resp")
|
||||||
requests_mock.get("https://example.com/still", text="resp")
|
requests_mock.get("https://example.com/still", text="resp")
|
||||||
yield requests_mock
|
return requests_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -179,4 +179,4 @@ async def mock_ha_fixture(hass, mock_pymodbus_return):
|
|||||||
@pytest.fixture(name="caplog_setup_text")
|
@pytest.fixture(name="caplog_setup_text")
|
||||||
async def caplog_setup_text_fixture(caplog):
|
async def caplog_setup_text_fixture(caplog):
|
||||||
"""Return setup log of integration."""
|
"""Return setup log of integration."""
|
||||||
yield caplog.text
|
return caplog.text
|
||||||
|
@ -115,7 +115,7 @@ async def mock_modbus_with_pymodbus_fixture(hass, caplog, do_config, mock_pymodb
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert DOMAIN in hass.config.components
|
assert DOMAIN in hass.config.components
|
||||||
assert caplog.text == ""
|
assert caplog.text == ""
|
||||||
yield mock_pymodbus
|
return mock_pymodbus
|
||||||
|
|
||||||
|
|
||||||
async def test_number_validator():
|
async def test_number_validator():
|
||||||
@ -582,7 +582,7 @@ async def mock_modbus_read_pymodbus_fixture(
|
|||||||
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL + 60))
|
freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL + 60))
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield mock_pymodbus
|
return mock_pymodbus
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -69,7 +69,7 @@ def mock_nextbus_predictions(mock_nextbus):
|
|||||||
instance = mock_nextbus.return_value
|
instance = mock_nextbus.return_value
|
||||||
instance.get_predictions_for_multi_stops.return_value = BASIC_RESULTS
|
instance.get_predictions_for_multi_stops.return_value = BASIC_RESULTS
|
||||||
|
|
||||||
yield instance.get_predictions_for_multi_stops
|
return instance.get_predictions_for_multi_stops
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -54,4 +54,4 @@ async def fixture_coils(mock_connection):
|
|||||||
|
|
||||||
mock_connection.read_coil = read_coil
|
mock_connection.read_coil = read_coil
|
||||||
mock_connection.read_coils = read_coils
|
mock_connection.read_coils = read_coils
|
||||||
yield coils
|
return coils
|
||||||
|
@ -82,4 +82,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aionotion):
|
|||||||
"""Define a fixture to set up notion."""
|
"""Define a fixture to set up notion."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -79,4 +79,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pyopenuv):
|
|||||||
"""Define a fixture to set up openuv."""
|
"""Define a fixture to set up openuv."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -290,7 +290,6 @@ def setup_comp(hass, mock_device_tracker_conf, mqtt_mock):
|
|||||||
hass.states.async_set("zone.inner_2", "zoning", INNER_ZONE)
|
hass.states.async_set("zone.inner_2", "zoning", INNER_ZONE)
|
||||||
|
|
||||||
hass.states.async_set("zone.outer", "zoning", OUTER_ZONE)
|
hass.states.async_set("zone.outer", "zoning", OUTER_ZONE)
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_owntracks(hass, config, ctx_cls=owntracks.OwnTracksContext):
|
async def setup_owntracks(hass, config, ctx_cls=owntracks.OwnTracksContext):
|
||||||
@ -334,7 +333,7 @@ def context(hass, setup_comp):
|
|||||||
"""Get the current context."""
|
"""Get the current context."""
|
||||||
return context
|
return context
|
||||||
|
|
||||||
yield get_context
|
return get_context
|
||||||
|
|
||||||
|
|
||||||
async def send_message(hass, topic, message, corrupt=False):
|
async def send_message(hass, topic, message, corrupt=False):
|
||||||
|
@ -83,4 +83,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aiopurpleair):
|
|||||||
"""Define a fixture to set up purpleair."""
|
"""Define a fixture to set up purpleair."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -70,4 +70,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aiorecollect):
|
|||||||
"""Define a fixture to set up recollect_waste."""
|
"""Define a fixture to set up recollect_waste."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -73,7 +73,7 @@ async def rfxtrx_fixture(hass):
|
|||||||
async def rfxtrx_automatic_fixture(hass, rfxtrx):
|
async def rfxtrx_automatic_fixture(hass, rfxtrx):
|
||||||
"""Fixture that starts up with automatic additions."""
|
"""Fixture that starts up with automatic additions."""
|
||||||
await setup_rfx_test_cfg(hass, automatic_add=True, devices={})
|
await setup_rfx_test_cfg(hass, automatic_add=True, devices={})
|
||||||
yield rfxtrx
|
return rfxtrx
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -86,4 +86,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aioridwell):
|
|||||||
"""Define a fixture to set up ridwell."""
|
"""Define a fixture to set up ridwell."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -25,7 +25,7 @@ def entities(hass):
|
|||||||
"""Initialize the test light."""
|
"""Initialize the test light."""
|
||||||
platform = getattr(hass.components, "test.light")
|
platform = getattr(hass.components, "test.light")
|
||||||
platform.init()
|
platform.init()
|
||||||
yield platform.ENTITIES[0:2]
|
return platform.ENTITIES[0:2]
|
||||||
|
|
||||||
|
|
||||||
async def test_config_yaml_alias_anchor(hass, entities, enable_custom_integrations):
|
async def test_config_yaml_alias_anchor(hass, entities, enable_custom_integrations):
|
||||||
|
@ -78,7 +78,7 @@ def message():
|
|||||||
0,
|
0,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
yield mailer
|
return mailer
|
||||||
|
|
||||||
|
|
||||||
HTML = """
|
HTML = """
|
||||||
|
@ -20,4 +20,4 @@ async def mock_connected_snooz(hass: HomeAssistant):
|
|||||||
device = await create_mock_snooz()
|
device = await create_mock_snooz()
|
||||||
entry = await create_mock_snooz_config_entry(hass, device)
|
entry = await create_mock_snooz_config_entry(hass, device)
|
||||||
|
|
||||||
yield SnoozFixture(entry, device)
|
return SnoozFixture(entry, device)
|
||||||
|
@ -286,7 +286,7 @@ async def fixture_snooz_fan_entity_id(
|
|||||||
) -> str:
|
) -> str:
|
||||||
"""Mock a Snooz fan entity and config entry."""
|
"""Mock a Snooz fan entity and config entry."""
|
||||||
|
|
||||||
yield get_fan_entity_id(hass, mock_connected_snooz.device)
|
return get_fan_entity_id(hass, mock_connected_snooz.device)
|
||||||
|
|
||||||
|
|
||||||
def get_fan_entity_id(hass: HomeAssistant, device: MockSnoozDevice) -> str:
|
def get_fan_entity_id(hass: HomeAssistant, device: MockSnoozDevice) -> str:
|
||||||
|
@ -23,7 +23,7 @@ DEVICE_2_ENTITY_ID = f"{MEDIA_PLAYER_DOMAIN}.my_soundtouch_2"
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device1_config() -> MockConfigEntry:
|
def device1_config() -> MockConfigEntry:
|
||||||
"""Mock SoundTouch device 1 config entry."""
|
"""Mock SoundTouch device 1 config entry."""
|
||||||
yield MockConfigEntry(
|
return MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=DEVICE_1_ID,
|
unique_id=DEVICE_1_ID,
|
||||||
data={
|
data={
|
||||||
@ -36,7 +36,7 @@ def device1_config() -> MockConfigEntry:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device2_config() -> MockConfigEntry:
|
def device2_config() -> MockConfigEntry:
|
||||||
"""Mock SoundTouch device 2 config entry."""
|
"""Mock SoundTouch device 2 config entry."""
|
||||||
yield MockConfigEntry(
|
return MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=DEVICE_2_ID,
|
unique_id=DEVICE_2_ID,
|
||||||
data={
|
data={
|
||||||
@ -155,7 +155,7 @@ def device1_requests_mock(
|
|||||||
requests_mock.get(f"{DEVICE_1_URL}/volume", text=device1_volume)
|
requests_mock.get(f"{DEVICE_1_URL}/volume", text=device1_volume)
|
||||||
requests_mock.get(f"{DEVICE_1_URL}/presets", text=device1_presets)
|
requests_mock.get(f"{DEVICE_1_URL}/presets", text=device1_presets)
|
||||||
requests_mock.get(f"{DEVICE_1_URL}/getZone", text=device1_zone_master)
|
requests_mock.get(f"{DEVICE_1_URL}/getZone", text=device1_zone_master)
|
||||||
yield requests_mock
|
return requests_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -229,7 +229,7 @@ def device1_requests_mock_key(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - key endpoint."""
|
"""Mock SoundTouch device 1 API - key endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/key")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/key")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -237,7 +237,7 @@ def device1_requests_mock_volume(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - volume endpoint."""
|
"""Mock SoundTouch device 1 API - volume endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/volume")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/volume")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -245,7 +245,7 @@ def device1_requests_mock_select(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - select endpoint."""
|
"""Mock SoundTouch device 1 API - select endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/select")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/select")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -253,7 +253,7 @@ def device1_requests_mock_set_zone(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - setZone endpoint."""
|
"""Mock SoundTouch device 1 API - setZone endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/setZone")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/setZone")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -261,7 +261,7 @@ def device1_requests_mock_add_zone_slave(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - addZoneSlave endpoint."""
|
"""Mock SoundTouch device 1 API - addZoneSlave endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/addZoneSlave")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/addZoneSlave")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -269,7 +269,7 @@ def device1_requests_mock_remove_zone_slave(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - removeZoneSlave endpoint."""
|
"""Mock SoundTouch device 1 API - removeZoneSlave endpoint."""
|
||||||
yield device1_requests_mock.post(f"{DEVICE_1_URL}/removeZoneSlave")
|
return device1_requests_mock.post(f"{DEVICE_1_URL}/removeZoneSlave")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -277,7 +277,7 @@ def device1_requests_mock_dlna(
|
|||||||
device1_requests_mock: Mocker,
|
device1_requests_mock: Mocker,
|
||||||
):
|
):
|
||||||
"""Mock SoundTouch device 1 API - DLNA endpoint."""
|
"""Mock SoundTouch device 1 API - DLNA endpoint."""
|
||||||
yield device1_requests_mock.post(f"http://{DEVICE_1_IP}:8091/AVTransport/Control")
|
return device1_requests_mock.post(f"http://{DEVICE_1_IP}:8091/AVTransport/Control")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -294,4 +294,4 @@ def device2_requests_mock_standby(
|
|||||||
requests_mock.get(f"{DEVICE_2_URL}/now_playing", text=device2_now_playing_standby)
|
requests_mock.get(f"{DEVICE_2_URL}/now_playing", text=device2_now_playing_standby)
|
||||||
requests_mock.get(f"{DEVICE_2_URL}/getZone", text=device2_zone_slave)
|
requests_mock.get(f"{DEVICE_2_URL}/getZone", text=device2_zone_slave)
|
||||||
|
|
||||||
yield requests_mock
|
return requests_mock
|
||||||
|
@ -14,7 +14,7 @@ def entities(hass):
|
|||||||
"""Initialize the test switch."""
|
"""Initialize the test switch."""
|
||||||
platform = getattr(hass.components, "test.switch")
|
platform = getattr(hass.components, "test.switch")
|
||||||
platform.init()
|
platform.init()
|
||||||
yield platform.ENTITIES
|
return platform.ENTITIES
|
||||||
|
|
||||||
|
|
||||||
async def test_methods(hass, entities, enable_custom_integrations):
|
async def test_methods(hass, entities, enable_custom_integrations):
|
||||||
|
@ -34,4 +34,4 @@ def fixture_dsm():
|
|||||||
dsm.surveillance_station.update = AsyncMock(return_value=True)
|
dsm.surveillance_station.update = AsyncMock(return_value=True)
|
||||||
dsm.upgrade.update = AsyncMock(return_value=True)
|
dsm.upgrade.update = AsyncMock(return_value=True)
|
||||||
|
|
||||||
yield dsm
|
return dsm
|
||||||
|
@ -30,4 +30,4 @@ async def start_ha(hass, count, domain, config, caplog):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def caplog_setup_text(caplog):
|
async def caplog_setup_text(caplog):
|
||||||
"""Return setup log of integration."""
|
"""Return setup log of integration."""
|
||||||
yield caplog.text
|
return caplog.text
|
||||||
|
@ -64,4 +64,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pytile):
|
|||||||
"""Define a fixture to set up tile."""
|
"""Define a fixture to set up tile."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
yield
|
|
||||||
|
@ -206,4 +206,4 @@ async def mock_config_entry(
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
yield entry
|
return entry
|
||||||
|
@ -26,5 +26,3 @@ def valid_config(hass: HomeAssistant, requests_mock):
|
|||||||
):
|
):
|
||||||
# Setup hub
|
# Setup hub
|
||||||
vultr.setup(hass, VALID_CONFIG)
|
vultr.setup(hass, VALID_CONFIG)
|
||||||
|
|
||||||
yield
|
|
||||||
|
@ -45,7 +45,7 @@ def load_hass_devices(hass: HomeAssistant):
|
|||||||
for config in CONFIGS:
|
for config in CONFIGS:
|
||||||
vultr.setup_platform(hass, config, add_entities, None)
|
vultr.setup_platform(hass, config, add_entities, None)
|
||||||
|
|
||||||
yield hass_devices
|
return hass_devices
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
|
@ -39,7 +39,6 @@ def mock_update_wrcerror_fixture(mock_wrc):
|
|||||||
"""Mock an update to the sensor failed with WRCError."""
|
"""Mock an update to the sensor failed with WRCError."""
|
||||||
obj = mock_wrc.return_value
|
obj = mock_wrc.return_value
|
||||||
obj.calc_all_routes_info.side_effect = WRCError("test")
|
obj.calc_all_routes_info.side_effect = WRCError("test")
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_update_keyerror")
|
@pytest.fixture(name="mock_update_keyerror")
|
||||||
@ -47,7 +46,6 @@ def mock_update_keyerror_fixture(mock_wrc):
|
|||||||
"""Mock an update to the sensor failed with KeyError."""
|
"""Mock an update to the sensor failed with KeyError."""
|
||||||
obj = mock_wrc.return_value
|
obj = mock_wrc.return_value
|
||||||
obj.calc_all_routes_info.side_effect = KeyError("test")
|
obj.calc_all_routes_info.side_effect = KeyError("test")
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -197,7 +197,7 @@ class TestInsight:
|
|||||||
"ontotal": 0,
|
"ontotal": 0,
|
||||||
"powerthreshold": 0,
|
"powerthreshold": 0,
|
||||||
}
|
}
|
||||||
yield pywemo_device
|
return pywemo_device
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"subscribed,state,expected_calls",
|
"subscribed,state,expected_calls",
|
||||||
|
@ -88,13 +88,13 @@ def get_aircon_mock(said):
|
|||||||
@pytest.fixture(name="mock_aircon1_api", autouse=False)
|
@pytest.fixture(name="mock_aircon1_api", autouse=False)
|
||||||
def fixture_mock_aircon1_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_aircon1_api(mock_auth_api, mock_appliances_manager_api):
|
||||||
"""Set up air conditioner API fixture."""
|
"""Set up air conditioner API fixture."""
|
||||||
yield get_aircon_mock(MOCK_SAID1)
|
return get_aircon_mock(MOCK_SAID1)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_aircon2_api", autouse=False)
|
@pytest.fixture(name="mock_aircon2_api", autouse=False)
|
||||||
def fixture_mock_aircon2_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_aircon2_api(mock_auth_api, mock_appliances_manager_api):
|
||||||
"""Set up air conditioner API fixture."""
|
"""Set up air conditioner API fixture."""
|
||||||
yield get_aircon_mock(MOCK_SAID2)
|
return get_aircon_mock(MOCK_SAID2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_aircon_api_instances", autouse=False)
|
@pytest.fixture(name="mock_aircon_api_instances", autouse=False)
|
||||||
@ -143,13 +143,13 @@ def get_sensor_mock(said):
|
|||||||
@pytest.fixture(name="mock_sensor1_api", autouse=False)
|
@pytest.fixture(name="mock_sensor1_api", autouse=False)
|
||||||
def fixture_mock_sensor1_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_sensor1_api(mock_auth_api, mock_appliances_manager_api):
|
||||||
"""Set up sensor API fixture."""
|
"""Set up sensor API fixture."""
|
||||||
yield get_sensor_mock(MOCK_SAID3)
|
return get_sensor_mock(MOCK_SAID3)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_sensor2_api", autouse=False)
|
@pytest.fixture(name="mock_sensor2_api", autouse=False)
|
||||||
def fixture_mock_sensor2_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_sensor2_api(mock_auth_api, mock_appliances_manager_api):
|
||||||
"""Set up sensor API fixture."""
|
"""Set up sensor API fixture."""
|
||||||
yield get_sensor_mock(MOCK_SAID4)
|
return get_sensor_mock(MOCK_SAID4)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_sensor_api_instances", autouse=False)
|
@pytest.fixture(name="mock_sensor_api_instances", autouse=False)
|
||||||
|
@ -205,7 +205,7 @@ util.get_local_ip = lambda: "127.0.0.1"
|
|||||||
def caplog_fixture(caplog):
|
def caplog_fixture(caplog):
|
||||||
"""Set log level to debug for tests using the caplog fixture."""
|
"""Set log level to debug for tests using the caplog fixture."""
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
yield caplog
|
return caplog
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope="module")
|
@pytest.fixture(autouse=True, scope="module")
|
||||||
@ -1103,7 +1103,7 @@ async def async_setup_recorder_instance(
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def recorder_mock(recorder_config, async_setup_recorder_instance, hass):
|
async def recorder_mock(recorder_config, async_setup_recorder_instance, hass):
|
||||||
"""Fixture with in-memory recorder."""
|
"""Fixture with in-memory recorder."""
|
||||||
yield await async_setup_recorder_instance(hass, recorder_config)
|
return await async_setup_recorder_instance(hass, recorder_config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -20,7 +20,7 @@ def integration():
|
|||||||
"requirements": [],
|
"requirements": [],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
yield integration
|
return integration
|
||||||
|
|
||||||
|
|
||||||
def test_validate_requirements_format_with_space(integration: Integration):
|
def test_validate_requirements_format_with_space(integration: Integration):
|
||||||
|
@ -45,7 +45,7 @@ def camera_client_fixture(hass, hass_client):
|
|||||||
)
|
)
|
||||||
hass.loop.run_until_complete(hass.async_block_till_done())
|
hass.loop.run_until_complete(hass.async_block_till_done())
|
||||||
|
|
||||||
yield hass.loop.run_until_complete(hass_client())
|
return hass.loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
async def test_get_clientsession_with_ssl(hass):
|
async def test_get_clientsession_with_ssl(hass):
|
||||||
|
@ -5,4 +5,5 @@ extend-select = [
|
|||||||
"PT001", # Use @pytest.fixture without parentheses
|
"PT001", # Use @pytest.fixture without parentheses
|
||||||
"PT013", # Found incorrect pytest import, use simple import pytest instead
|
"PT013", # Found incorrect pytest import, use simple import pytest instead
|
||||||
"PT015", # Assertion always fails, replace with pytest.fail()
|
"PT015", # Assertion always fails, replace with pytest.fail()
|
||||||
|
"PT022", # No teardown in fixture, replace useless yield with return
|
||||||
]
|
]
|
Loading…
x
Reference in New Issue
Block a user