Simplify nest test patch using new keyword (#62336)

This commit is contained in:
Allen Porter 2021-12-19 11:45:04 -08:00 committed by GitHub
parent 9017d35e73
commit 368e16f189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,7 @@ import datetime
from http import HTTPStatus from http import HTTPStatus
import shutil import shutil
from typing import Generator from typing import Generator
from unittest.mock import Mock, patch from unittest.mock import patch
import uuid import uuid
import aiohttp import aiohttp
@ -78,9 +78,7 @@ IMAGE_AUTHORIZATION_HEADERS = {"Authorization": "Basic g.0.eventToken"}
def cleanup_media_storage(hass): def cleanup_media_storage(hass):
"""Test cleanup, remove any media storage persisted during the test.""" """Test cleanup, remove any media storage persisted during the test."""
tmp_path = str(uuid.uuid4()) tmp_path = str(uuid.uuid4())
m = Mock(spec=float) with patch("homeassistant.components.nest.media_source.MEDIA_PATH", new=tmp_path):
m.return_value = tmp_path
with patch("homeassistant.components.nest.media_source.MEDIA_PATH", new_callable=m):
yield yield
shutil.rmtree(hass.config.path(tmp_path), ignore_errors=True) shutil.rmtree(hass.config.path(tmp_path), ignore_errors=True)
@ -725,11 +723,9 @@ async def test_multiple_devices(hass, auth, hass_client):
@pytest.fixture @pytest.fixture
def event_store() -> Generator[None, None, None]: def event_store() -> Generator[None, None, None]:
"""Persist changes to event store immediately.""" """Persist changes to event store immediately."""
m = Mock(spec=float)
m.return_value = 0
with patch( with patch(
"homeassistant.components.nest.media_source.STORAGE_SAVE_DELAY_SECONDS", "homeassistant.components.nest.media_source.STORAGE_SAVE_DELAY_SECONDS",
new_callable=m, new=0,
): ):
yield yield
@ -947,9 +943,7 @@ async def test_camera_event_media_eviction(hass, auth, hass_client):
"""Test media files getting evicted from the cache.""" """Test media files getting evicted from the cache."""
# Set small cache size for testing eviction # Set small cache size for testing eviction
m = Mock(spec=float) with patch("homeassistant.components.nest.EVENT_MEDIA_CACHE_SIZE", new=5):
m.return_value = 5
with patch("homeassistant.components.nest.EVENT_MEDIA_CACHE_SIZE", new_callable=m):
subscriber = await async_setup_devices( subscriber = await async_setup_devices(
hass, hass,
auth, auth,