Skip to content

Commit

Permalink
[create-pull-request] automated change (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: MatthewFlamm <[email protected]>
  • Loading branch information
MatthewFlamm and MatthewFlamm authored Sep 30, 2021
1 parent 465fdb8 commit b362786
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pytest-homeassistant-custom-component

![HA core version](https://img.shields.io/static/v1?label=HA+core+version&message=2021.9.0b2&labelColor=blue)
![HA core version](https://img.shields.io/static/v1?label=HA+core+version&message=2021.10.0b1&labelColor=blue)

Package to automatically extract testing plugins from Home Assistant for custom component testing.
The goal is to provide the same functionality as the tests in home-assistant/core.
Expand Down
4 changes: 4 additions & 0 deletions pytest_homeassistant_custom_component/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,14 @@ def __init__(
def add_to_hass(self, hass):
"""Test helper to add entry to hass."""
hass.config_entries._entries[self.entry_id] = self
hass.config_entries._domain_index.setdefault(self.domain, []).append(
self.entry_id
)

def add_to_manager(self, manager):
"""Test helper to add entry to entry manager."""
manager._entries[self.entry_id] = self
manager._domain_index.setdefault(self.domain, []).append(self.entry_id)


def patch_yaml_files(files_dict, endswith=True):
Expand Down
4 changes: 2 additions & 2 deletions pytest_homeassistant_custom_component/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Final

MAJOR_VERSION: Final = 2021
MINOR_VERSION: Final = 9
PATCH_VERSION: Final = "0b2"
MINOR_VERSION: Final = 10
PATCH_VERSION: Final = "0b1"
__short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__: Final = f"{__short_version__}.{PATCH_VERSION}"
31 changes: 27 additions & 4 deletions pytest_homeassistant_custom_component/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ async def auth_client():
return auth_client


@pytest.fixture
def hass_client_no_auth(hass, aiohttp_client):
"""Return an unauthenticated HTTP client."""

async def client():
"""Return an authenticated client."""
return await aiohttp_client(hass.http.app)

return client


@pytest.fixture
def current_request():
"""Mock current request."""
Expand Down Expand Up @@ -481,11 +492,23 @@ async def mqtt_mock(hass, mqtt_client_mock, mqtt_config):
return component


@pytest.fixture
def mock_get_source_ip():
"""Mock network util's async_get_source_ip."""
with patch(
"homeassistant.components.network.util.async_get_source_ip",
return_value="10.10.10.10",
):
yield


@pytest.fixture
def mock_zeroconf():
"""Mock zeroconf."""
with patch("homeassistant.components.zeroconf.models.HaZeroconf") as mock_zc:
yield mock_zc.return_value
with patch("homeassistant.components.zeroconf.HaZeroconf", autospec=True), patch(
"homeassistant.components.zeroconf.HaAsyncServiceBrowser", autospec=True
):
yield


@pytest.fixture
Expand Down Expand Up @@ -617,9 +640,9 @@ def enable_statistics():
def hass_recorder(enable_statistics, hass_storage):
"""Home Assistant fixture with in-memory recorder."""
hass = get_test_home_assistant()
stats = recorder.Recorder.async_hourly_statistics if enable_statistics else None
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None
with patch(
"homeassistant.components.recorder.Recorder.async_hourly_statistics",
"homeassistant.components.recorder.Recorder.async_periodic_statistics",
side_effect=stats,
autospec=True,
):
Expand Down
3 changes: 2 additions & 1 deletion pytest_homeassistant_custom_component/test_util/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from aiohttp import ClientSession
from aiohttp.client_exceptions import ClientError, ClientResponseError
from aiohttp.streams import StreamReader
from multidict import CIMultiDict
from yarl import URL

from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE
Expand Down Expand Up @@ -183,7 +184,7 @@ def __init__(
self.response = response
self.exc = exc
self.side_effect = side_effect
self._headers = headers or {}
self._headers = CIMultiDict(headers or {})
self._cookies = {}

if cookies:
Expand Down
6 changes: 2 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# This file is originally from homeassistant/core and modified by pytest-homeassistant-custom-component.
codecov==2.1.12
mypy==0.910
pre-commit==2.14.0
pylint==2.10.2
pre-commit==2.15.0
pylint==2.11.1
types-croniter==1.0.0
types-backports==0.1.3
types-certifi==0.1.4
types-chardet==0.1.5
types-cryptography==3.3.2
types-decorator==0.1.7
types-emoji==1.2.4
types-enum34==0.1.8
types-ipaddress==0.1.5
types-jwt==0.1.3
types-pkg-resources==0.1.3
types-python-slugify==0.1.2
types-pytz==2021.1.2
Expand Down
8 changes: 4 additions & 4 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
coverage==5.5
jsonpickle==1.4.1
mock-open==1.4.0
pipdeptree==1.0.0
pipdeptree==2.1.0
pylint-strict-informational==0.1
pytest-aiohttp==0.3.0
pytest-cov==2.12.1
pytest-test-groups==1.0.3
pytest-sugar==0.9.4
pytest-timeout==1.4.2
pytest-xdist==2.2.1
pytest==6.2.4
pytest-xdist==2.4.0
pytest==6.2.5
requests_mock==1.9.2
responses==0.12.0
respx==0.17.0
stdlib-list==0.7.0
tqdm==4.49.0
homeassistant==2021.9.0b2
homeassistant==2021.10.0b1
sqlalchemy==1.4.23

0 comments on commit b362786

Please sign in to comment.