Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions script/scaffold/templates/config_flow/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test the NEW_NAME config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch

import pytest


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test the NEW_NAME config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch

import pytest
Expand All @@ -10,14 +9,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
Expand Down
14 changes: 14 additions & 0 deletions script/scaffold/templates/config_flow_helper/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test the NEW_NAME config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch

import pytest


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test the NEW_NAME config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock

import pytest

Expand All @@ -11,14 +10,7 @@

from tests.common import MockConfigEntry


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


@pytest.mark.parametrize("platform", ("sensor",))
Expand Down
11 changes: 10 additions & 1 deletion tests/components/nibe_heatpump/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test configuration for Nibe Heat Pump."""
from collections.abc import AsyncIterator, Iterable
from collections.abc import AsyncIterator, Generator, Iterable
from contextlib import ExitStack
from typing import Any
from unittest.mock import AsyncMock, Mock, patch
Expand All @@ -10,6 +10,15 @@
import pytest


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Make sure we never actually run setup."""
with patch(
"homeassistant.components.nibe_heatpump.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture(autouse=True, name="mock_connection_constructor")
async def fixture_mock_connection_constructor():
"""Make sure we have a dummy connection."""
Expand Down
10 changes: 2 additions & 8 deletions tests/components/nibe_heatpump/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test the Nibe Heat Pump config flow."""
from unittest.mock import Mock, patch
from unittest.mock import Mock

from nibe.coil import Coil
from nibe.exceptions import (
Expand Down Expand Up @@ -32,13 +32,7 @@
}


@pytest.fixture(autouse=True, name="mock_setup_entry")
async def fixture_mock_setup():
"""Make sure we never actually run setup."""
with patch(
"homeassistant.components.nibe_heatpump.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


async def _get_connection_form(
Expand Down
12 changes: 11 additions & 1 deletion tests/components/onewire/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provide common 1-Wire fixtures."""
from unittest.mock import MagicMock, patch
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch

from pyownet.protocol import ConnError
import pytest
Expand All @@ -14,6 +15,15 @@
from tests.common import MockConfigEntry


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.onewire.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture(name="device_id", params=MOCK_OWPROXY_DEVICES.keys())
def get_device_id(request: pytest.FixtureRequest) -> str:
"""Parametrize device id."""
Expand Down
10 changes: 1 addition & 9 deletions tests/components/onewire/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Tests for 1-Wire config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch

from pyownet import protocol
Expand All @@ -19,14 +18,7 @@

from .const import MOCK_OWPROXY_DEVICES


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.onewire.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


@pytest.fixture
Expand Down
14 changes: 13 additions & 1 deletion tests/components/philips_js/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Standard setup for tests."""
from unittest.mock import create_autospec, patch
from collections.abc import Generator
from unittest.mock import AsyncMock, create_autospec, patch

from haphilipsjs import PhilipsTV
import pytest
Expand All @@ -11,6 +12,17 @@
from tests.common import MockConfigEntry, mock_device_registry


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Disable component setup."""
with patch(
"homeassistant.components.philips_js.async_setup_entry", return_value=True
) as mock_setup_entry, patch(
"homeassistant.components.philips_js.async_unload_entry", return_value=True
):
yield mock_setup_entry


@pytest.fixture(autouse=True)
async def setup_notification(hass):
"""Configure notification system."""
Expand Down
13 changes: 2 additions & 11 deletions tests/components/philips_js/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test the Philips TV config flow."""
from unittest.mock import ANY, patch
from unittest.mock import ANY

from haphilipsjs import PairingFailure
import pytest
Expand All @@ -19,16 +19,7 @@

from tests.common import MockConfigEntry


@pytest.fixture(autouse=True, name="mock_setup_entry")
def mock_setup_entry_fixture():
"""Disable component setup."""
with patch(
"homeassistant.components.philips_js.async_setup_entry", return_value=True
) as mock_setup_entry, patch(
"homeassistant.components.philips_js.async_unload_entry", return_value=True
):
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


@pytest.fixture
Expand Down
12 changes: 11 additions & 1 deletion tests/components/renault/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Provide common Renault fixtures."""
from collections.abc import Generator
import contextlib
from types import MappingProxyType
from typing import Any
from unittest.mock import patch
from unittest.mock import AsyncMock, patch

import pytest
from renault_api.kamereon import exceptions, schemas
Expand All @@ -18,6 +19,15 @@
from tests.common import MockConfigEntry, load_fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.renault.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture(name="vehicle_type", params=MOCK_VEHICLES.keys())
def get_vehicle_type(request: pytest.FixtureRequest) -> str:
"""Parametrize vehicle type."""
Expand Down
9 changes: 1 addition & 8 deletions tests/components/renault/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@

from tests.common import load_fixture


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> AsyncMock:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.renault.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


async def test_config_flow_single_account(
Expand Down
11 changes: 10 additions & 1 deletion tests/components/samsungtv/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Fixtures for Samsung TV."""
from __future__ import annotations

from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Generator
from datetime import datetime
from socket import AddressFamily
from typing import Any
Expand All @@ -25,6 +25,15 @@
from .const import SAMPLE_DEVICE_INFO_UE48JU6400, SAMPLE_DEVICE_INFO_WIFI


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.samsungtv.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture(autouse=True)
async def silent_ssdp_scanner(hass):
"""Start SSDP component and get Scanner, prevent actual SSDP traffic."""
Expand Down
10 changes: 1 addition & 9 deletions tests/components/samsungtv/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Tests for Samsung TV config flow."""
from collections.abc import Generator
import socket
from unittest.mock import ANY, AsyncMock, Mock, call, patch

Expand Down Expand Up @@ -216,14 +215,7 @@
"timeout": TIMEOUT_WEBSOCKET,
}


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.samsungtv.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


@pytest.mark.usefixtures("remote", "rest_api_failing")
Expand Down
11 changes: 10 additions & 1 deletion tests/components/sfr_box/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Provide common SFR Box fixtures."""
from collections.abc import Generator
import json
from unittest.mock import patch
from unittest.mock import AsyncMock, patch

import pytest
from sfrbox_api.models import DslInfo, SystemInfo
Expand All @@ -14,6 +14,15 @@
from tests.common import MockConfigEntry, load_fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sfr_box.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture(name="config_entry")
def get_config_entry(hass: HomeAssistant) -> ConfigEntry:
"""Create and register mock config entry."""
Expand Down
10 changes: 1 addition & 9 deletions tests/components/sfr_box/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test the SFR Box config flow."""
from collections.abc import Generator
import json
from unittest.mock import AsyncMock, patch

Expand All @@ -15,14 +14,7 @@

from tests.common import load_fixture


@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sfr_box.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")


async def test_config_flow_skip_auth(
Expand Down
11 changes: 10 additions & 1 deletion tests/components/sleepiq/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from collections.abc import Generator
from unittest.mock import MagicMock, create_autospec, patch
from unittest.mock import AsyncMock, MagicMock, create_autospec, patch

from asyncsleepiq import (
Side,
Expand Down Expand Up @@ -40,6 +40,15 @@
}


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sleepiq.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry


@pytest.fixture
def mock_bed() -> MagicMock:
"""Mock a SleepIQBed object with sleepers and lights."""
Expand Down
Loading