Repository: home-assistant/core
File: tests/components/hassio/test_init.py (Python)

Code before:

    with pytest.raises(Invalid):
        await hass.services.async_call(
            "hassio", f"{app_or_addon}_start", {app_or_addon: "does_not_exist"}
        )
    with pytest.raises(Invalid):
        await hass.services.async_call(
            "hassio",
            f"{app_or_addon}_stdin",
            {app_or_addon: "does_not_exist", "input": "test"},
        )


@pytest.mark.parametrize(
    "service",
    ["backup_partial", "restore_partial"],
)
@pytest.mark.usefixtures("addon_installed")
async def test_service_calls_apps_addons_exclusive(
    hass: HomeAssistant,
    supervisor_is_connected: AsyncMock,
    service: str,
) -> None:
    """Test that apps and addons parameters are mutually exclusive."""
    supervisor_is_connected.side_effect = SupervisorError
    with patch.dict(os.environ, MOCK_ENVIRON):
        assert await async_setup_component(hass, "hassio", {})
        await hass.async_block_till_done()

    service_data: dict[str, Any] = {
        "apps": ["test"],
        "addons": ["test"],
    }
    if service == "restore_partial":
        service_data["slug"] = "test"

    with pytest.raises(
        Invalid, match="two or more values in the same group of exclusion"
    ):
        await hass.services.async_call("hassio", service, service_data)


@pytest.mark.parametrize(
    "app_or_addon",
    ["app", "addon"],
)
async def test_addon_service_call_with_complex_slug(
    hass: HomeAssistant,
    aioclient_mock: AiohttpClientMocker,
    supervisor_is_connected: AsyncMock,
    app_or_addon: str,

Review comment (suggestion):
```suggestion
@pytest.mark.parametrize(
    ("service", "service_data"),
    [
        (
            "backup_partial",
            {"apps": ["test"], "addons": ["test"]},
        ),
        (
            "restore_partial",
            {"apps": ["test"], "addons": ["test"], "slug": "test"},
        ),
    ],
)
```

Code after:

    with pytest.raises(Invalid):
        await hass.services.async_call(
            "hassio", f"{app_or_addon}_start", {app_or_addon: "does_not_exist"}
        )
    with pytest.raises(Invalid):
        await hass.services.async_call(
            "hassio",
            f"{app_or_addon}_stdin",
            {app_or_addon: "does_not_exist", "input": "test"},
        )


@pytest.mark.parametrize(
    ("service", "service_data"),
    [
        (
            "backup_partial",
            {"apps": ["test"], "addons": ["test"]},
        ),
        (
            "restore_partial",
            {"apps": ["test"], "addons": ["test"], "slug": "test"},
        ),
    ],
)
@pytest.mark.usefixtures("addon_installed")
async def test_service_calls_apps_addons_exclusive(
    hass: HomeAssistant,
    supervisor_is_connected: AsyncMock,
    service: str,
    service_data: dict[str, Any],
) -> None:
    """Test that apps and addons parameters are mutually exclusive."""
    supervisor_is_connected.side_effect = SupervisorError
    with patch.dict(os.environ, MOCK_ENVIRON):
        assert await async_setup_component(hass, "hassio", {})
        await hass.async_block_till_done()

    with pytest.raises(
        Invalid, match="two or more values in the same group of exclusion"
    ):
        await hass.services.async_call("hassio", service, service_data)


@pytest.mark.parametrize(
    "app_or_addon",
    ["app", "addon"],
)
async def test_addon_service_call_with_complex_slug(
    hass: HomeAssistant,