Centralise MockStreamReaderChunked helper (#145404)

centralize MockStreamReaderChunked helper
This commit is contained in:
Michael 2025-05-22 08:22:02 +02:00 committed by GitHub
parent bffbd5607b
commit 66a6e55310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 30 deletions

View File

@ -28,6 +28,14 @@ class MockStreamReader:
return self._content.read(byte_count)
class MockStreamReaderChunked(MockStreamReader):
"""Mock a stream reader with simulated chunked data."""
async def readchunk(self) -> tuple[bytes, bool]:
"""Read bytes."""
return (self._content.read(), False)
class MockPayloadWriter:
"""Small mock to imitate payload writer."""

View File

@ -24,20 +24,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.backup import async_initialize_backup
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.setup import async_setup_component
from homeassistant.util.aiohttp import MockStreamReader
from homeassistant.util.aiohttp import MockStreamReaderChunked
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator, MagicMock, WebSocketGenerator
class MockStreamReaderChunked(MockStreamReader):
"""Mock a stream reader with simulated chunked data."""
async def readchunk(self) -> tuple[bytes, bool]:
"""Read bytes."""
return (self._content.read(), False)
@pytest.fixture(autouse=True)
async def setup_integration(
hass: HomeAssistant,

View File

@ -1,19 +1,10 @@
"""Tests for the Immich integration."""
from homeassistant.core import HomeAssistant
from homeassistant.util.aiohttp import MockStreamReader
from tests.common import MockConfigEntry
class MockStreamReaderChunked(MockStreamReader):
"""Mock a stream reader with simulated chunked data."""
async def readchunk(self) -> tuple[bytes, bool]:
"""Read bytes."""
return (self._content.read(), False)
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Fixture for setting up the component."""
config_entry.add_to_hass(hass)

View File

@ -23,8 +23,8 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util.aiohttp import MockStreamReaderChunked
from . import MockStreamReaderChunked
from .const import MOCK_ALBUM_WITH_ASSETS, MOCK_ALBUM_WITHOUT_ASSETS
from tests.common import MockConfigEntry

View File

@ -23,9 +23,9 @@ from homeassistant.components.media_source import (
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util.aiohttp import MockRequest
from homeassistant.util.aiohttp import MockRequest, MockStreamReaderChunked
from . import MockStreamReaderChunked, setup_integration
from . import setup_integration
from .const import MOCK_ALBUM_WITHOUT_ASSETS
from tests.common import MockConfigEntry

View File

@ -34,7 +34,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.backup import async_initialize_backup
from homeassistant.setup import async_setup_component
from homeassistant.util.aiohttp import MockStreamReader
from homeassistant.util.aiohttp import MockStreamReader, MockStreamReaderChunked
from .common import mock_dsm_information
from .consts import HOST, MACS, PASSWORD, PORT, USE_SSL, USERNAME
@ -45,14 +45,6 @@ from tests.typing import ClientSessionGenerator, WebSocketGenerator
BASE_FILENAME = "Automatic_backup_2025.2.0.dev0_2025-01-09_20.14_35457323"
class MockStreamReaderChunked(MockStreamReader):
"""Mock a stream reader with simulated chunked data."""
async def readchunk(self) -> tuple[bytes, bool]:
"""Read bytes."""
return (self._content.read(), False)
async def _mock_download_file(path: str, filename: str) -> MockStreamReader:
if filename == f"{BASE_FILENAME}_meta.json":
return MockStreamReader(