forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
mock_platform
for event entity component tests instead of `hass…
….components` (home-assistant#113667)
- Loading branch information
Showing
4 changed files
with
61 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Fixtures for the event entity component tests.""" | ||
import logging | ||
|
||
import pytest | ||
|
||
from homeassistant.components.event import DOMAIN, EventEntity | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType | ||
|
||
from .const import TEST_DOMAIN | ||
|
||
from tests.common import MockEntity, MockPlatform, mock_platform | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class MockEventEntity(MockEntity, EventEntity): | ||
"""Mock EventEntity class.""" | ||
|
||
@property | ||
def event_types(self) -> list[str]: | ||
"""Return a list of possible events.""" | ||
return self._handle("event_types") | ||
|
||
|
||
@pytest.fixture | ||
async def mock_event_platform(hass: HomeAssistant) -> None: | ||
"""Mock the event entity platform.""" | ||
|
||
async def async_setup_platform( | ||
hass: HomeAssistant, | ||
config: ConfigType, | ||
async_add_entities: AddEntitiesCallback, | ||
discovery_info: DiscoveryInfoType | None = None, | ||
) -> None: | ||
"""Set up test event platform.""" | ||
async_add_entities( | ||
[ | ||
MockEventEntity( | ||
name="doorbell", | ||
unique_id="unique_doorbell", | ||
event_types=["short_press", "long_press"], | ||
), | ||
] | ||
) | ||
|
||
mock_platform( | ||
hass, | ||
f"{TEST_DOMAIN}.{DOMAIN}", | ||
MockPlatform(async_setup_platform=async_setup_platform), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Constants for the event entity component tests.""" | ||
|
||
TEST_DOMAIN = "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.