Add capsys to enforce-type-hints plugin (#120653)
This commit is contained in:
parent
eb2d2ce1b3
commit
f4b76406f2
4 changed files with 34 additions and 10 deletions
|
@ -79,7 +79,7 @@ _INNER_MATCH_POSSIBILITIES = [i + 1 for i in range(5)]
|
||||||
_TYPE_HINT_MATCHERS.update(
|
_TYPE_HINT_MATCHERS.update(
|
||||||
{
|
{
|
||||||
f"x_of_y_{i}": re.compile(
|
f"x_of_y_{i}": re.compile(
|
||||||
rf"^(\w+)\[{_INNER_MATCH}" + f", {_INNER_MATCH}" * (i - 1) + r"\]$"
|
rf"^([\w\.]+)\[{_INNER_MATCH}" + f", {_INNER_MATCH}" * (i - 1) + r"\]$"
|
||||||
)
|
)
|
||||||
for i in _INNER_MATCH_POSSIBILITIES
|
for i in _INNER_MATCH_POSSIBILITIES
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ _TEST_FIXTURES: dict[str, list[str] | str] = {
|
||||||
"area_registry": "AreaRegistry",
|
"area_registry": "AreaRegistry",
|
||||||
"async_setup_recorder_instance": "RecorderInstanceGenerator",
|
"async_setup_recorder_instance": "RecorderInstanceGenerator",
|
||||||
"caplog": "pytest.LogCaptureFixture",
|
"caplog": "pytest.LogCaptureFixture",
|
||||||
|
"capsys": "pytest.CaptureFixture[str]",
|
||||||
"current_request_with_host": "None",
|
"current_request_with_host": "None",
|
||||||
"device_registry": "DeviceRegistry",
|
"device_registry": "DeviceRegistry",
|
||||||
"enable_bluetooth": "None",
|
"enable_bluetooth": "None",
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.srp_energy.const import CONF_IS_TOU, DOMAIN
|
from homeassistant.components.srp_energy.const import CONF_IS_TOU, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
||||||
from homeassistant.const import CONF_ID, CONF_PASSWORD, CONF_SOURCE, CONF_USERNAME
|
from homeassistant.const import CONF_ID, CONF_PASSWORD, CONF_SOURCE, CONF_USERNAME
|
||||||
|
@ -23,8 +25,9 @@ from . import (
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_srp_energy_config_flow")
|
||||||
async def test_show_form(
|
async def test_show_form(
|
||||||
hass: HomeAssistant, mock_srp_energy_config_flow: MagicMock, capsys
|
hass: HomeAssistant, capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test show configuration form."""
|
"""Test show configuration form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -140,7 +143,7 @@ async def test_flow_entry_already_configured(
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_multiple_configs(
|
async def test_flow_multiple_configs(
|
||||||
hass: HomeAssistant, init_integration: MockConfigEntry, capsys
|
hass: HomeAssistant, init_integration: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test multiple config entries."""
|
"""Test multiple config entries."""
|
||||||
# Verify mock config setup from fixture
|
# Verify mock config setup from fixture
|
||||||
|
|
|
@ -55,6 +55,7 @@ def test_regex_get_module_platform(
|
||||||
("list[dict[str, Any]]", 1, ("list", "dict[str, Any]")),
|
("list[dict[str, Any]]", 1, ("list", "dict[str, Any]")),
|
||||||
("tuple[bytes | None, str | None]", 2, ("tuple", "bytes | None", "str | None")),
|
("tuple[bytes | None, str | None]", 2, ("tuple", "bytes | None", "str | None")),
|
||||||
("Callable[[], TestServer]", 2, ("Callable", "[]", "TestServer")),
|
("Callable[[], TestServer]", 2, ("Callable", "[]", "TestServer")),
|
||||||
|
("pytest.CaptureFixture[str]", 1, ("pytest.CaptureFixture", "str")),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_regex_x_of_y_i(
|
def test_regex_x_of_y_i(
|
||||||
|
@ -1264,6 +1265,7 @@ def test_pytest_fixture(linter: UnittestLinter, type_hint_checker: BaseChecker)
|
||||||
def sample_fixture( #@
|
def sample_fixture( #@
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
aiohttp_server: Callable[[], TestServer],
|
aiohttp_server: Callable[[], TestServer],
|
||||||
unused_tcp_port_factory: Callable[[], int],
|
unused_tcp_port_factory: Callable[[], int],
|
||||||
enable_custom_integrations: None,
|
enable_custom_integrations: None,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing_extensions import Generator
|
||||||
|
|
||||||
from homeassistant.auth.providers import homeassistant as hass_auth
|
from homeassistant.auth.providers import homeassistant as hass_auth
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -15,7 +16,7 @@ from tests.common import register_auth_provider
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def reset_log_level():
|
def reset_log_level() -> Generator[None]:
|
||||||
"""Reset log level after each test case."""
|
"""Reset log level after each test case."""
|
||||||
logger = logging.getLogger("homeassistant.core")
|
logger = logging.getLogger("homeassistant.core")
|
||||||
orig_level = logger.level
|
orig_level = logger.level
|
||||||
|
@ -24,7 +25,7 @@ def reset_log_level():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def provider(hass):
|
def provider(hass: HomeAssistant) -> hass_auth.HassAuthProvider:
|
||||||
"""Home Assistant auth provider."""
|
"""Home Assistant auth provider."""
|
||||||
provider = hass.loop.run_until_complete(
|
provider = hass.loop.run_until_complete(
|
||||||
register_auth_provider(hass, {"type": "homeassistant"})
|
register_auth_provider(hass, {"type": "homeassistant"})
|
||||||
|
@ -33,7 +34,11 @@ def provider(hass):
|
||||||
return provider
|
return provider
|
||||||
|
|
||||||
|
|
||||||
async def test_list_user(hass: HomeAssistant, provider, capsys) -> None:
|
async def test_list_user(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
provider: hass_auth.HassAuthProvider,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
|
) -> None:
|
||||||
"""Test we can list users."""
|
"""Test we can list users."""
|
||||||
data = provider.data
|
data = provider.data
|
||||||
data.add_auth("test-user", "test-pass")
|
data.add_auth("test-user", "test-pass")
|
||||||
|
@ -47,7 +52,10 @@ async def test_list_user(hass: HomeAssistant, provider, capsys) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def test_add_user(
|
async def test_add_user(
|
||||||
hass: HomeAssistant, provider, capsys, hass_storage: dict[str, Any]
|
hass: HomeAssistant,
|
||||||
|
provider: hass_auth.HassAuthProvider,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can add a user."""
|
"""Test we can add a user."""
|
||||||
data = provider.data
|
data = provider.data
|
||||||
|
@ -64,7 +72,11 @@ async def test_add_user(
|
||||||
data.validate_login("paulus", "test-pass")
|
data.validate_login("paulus", "test-pass")
|
||||||
|
|
||||||
|
|
||||||
async def test_validate_login(hass: HomeAssistant, provider, capsys) -> None:
|
async def test_validate_login(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
provider: hass_auth.HassAuthProvider,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
|
) -> None:
|
||||||
"""Test we can validate a user login."""
|
"""Test we can validate a user login."""
|
||||||
data = provider.data
|
data = provider.data
|
||||||
data.add_auth("test-user", "test-pass")
|
data.add_auth("test-user", "test-pass")
|
||||||
|
@ -89,7 +101,10 @@ async def test_validate_login(hass: HomeAssistant, provider, capsys) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def test_change_password(
|
async def test_change_password(
|
||||||
hass: HomeAssistant, provider, capsys, hass_storage: dict[str, Any]
|
hass: HomeAssistant,
|
||||||
|
provider: hass_auth.HassAuthProvider,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can change a password."""
|
"""Test we can change a password."""
|
||||||
data = provider.data
|
data = provider.data
|
||||||
|
@ -108,7 +123,10 @@ async def test_change_password(
|
||||||
|
|
||||||
|
|
||||||
async def test_change_password_invalid_user(
|
async def test_change_password_invalid_user(
|
||||||
hass: HomeAssistant, provider, capsys, hass_storage: dict[str, Any]
|
hass: HomeAssistant,
|
||||||
|
provider: hass_auth.HassAuthProvider,
|
||||||
|
capsys: pytest.CaptureFixture[str],
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test changing password of non-existing user."""
|
"""Test changing password of non-existing user."""
|
||||||
data = provider.data
|
data = provider.data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue