mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Improve type hints in google_pubsub tests (#121172)
* Improve type hints in google_pubsub tests * Remove from .coveragerc
This commit is contained in:
parent
aa74ad0061
commit
8aedb1201d
@ -487,7 +487,6 @@ omit =
|
|||||||
homeassistant/components/goodwe/sensor.py
|
homeassistant/components/goodwe/sensor.py
|
||||||
homeassistant/components/google_cloud/tts.py
|
homeassistant/components/google_cloud/tts.py
|
||||||
homeassistant/components/google_maps/device_tracker.py
|
homeassistant/components/google_maps/device_tracker.py
|
||||||
homeassistant/components/google_pubsub/__init__.py
|
|
||||||
homeassistant/components/gpsd/__init__.py
|
homeassistant/components/gpsd/__init__.py
|
||||||
homeassistant/components/gpsd/sensor.py
|
homeassistant/components/gpsd/sensor.py
|
||||||
homeassistant/components/greenwave/light.py
|
homeassistant/components/greenwave/light.py
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
"""The tests for the Google Pub/Sub component."""
|
"""The tests for the Google Pub/Sub component."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
from unittest import mock
|
from unittest.mock import MagicMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -40,21 +41,21 @@ async def test_nested() -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, name="mock_client")
|
@pytest.fixture(autouse=True, name="mock_client")
|
||||||
def mock_client_fixture():
|
def mock_client_fixture() -> Generator[MagicMock]:
|
||||||
"""Mock the pubsub client."""
|
"""Mock the pubsub client."""
|
||||||
with mock.patch(f"{GOOGLE_PUBSUB_PATH}.PublisherClient") as client:
|
with patch(f"{GOOGLE_PUBSUB_PATH}.PublisherClient") as client:
|
||||||
setattr(
|
setattr(
|
||||||
client,
|
client,
|
||||||
"from_service_account_json",
|
"from_service_account_json",
|
||||||
mock.MagicMock(return_value=mock.MagicMock()),
|
MagicMock(return_value=MagicMock()),
|
||||||
)
|
)
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, name="mock_is_file")
|
@pytest.fixture(autouse=True, name="mock_is_file")
|
||||||
def mock_is_file_fixture():
|
def mock_is_file_fixture() -> Generator[MagicMock]:
|
||||||
"""Mock os.path.isfile."""
|
"""Mock os.path.isfile."""
|
||||||
with mock.patch(f"{GOOGLE_PUBSUB_PATH}.os.path.isfile") as is_file:
|
with patch(f"{GOOGLE_PUBSUB_PATH}.os.path.isfile") as is_file:
|
||||||
is_file.return_value = True
|
is_file.return_value = True
|
||||||
yield is_file
|
yield is_file
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ def mock_is_file_fixture():
|
|||||||
def mock_json(hass, monkeypatch):
|
def mock_json(hass, monkeypatch):
|
||||||
"""Mock the event bus listener and os component."""
|
"""Mock the event bus listener and os component."""
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
f"{GOOGLE_PUBSUB_PATH}.json.dumps", mock.Mock(return_value=mock.MagicMock())
|
f"{GOOGLE_PUBSUB_PATH}.json.dumps", Mock(return_value=MagicMock())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user