From 8aedb1201d7872adfe84e816f03044c997e9b1f8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:31:35 +0200 Subject: [PATCH] Improve type hints in google_pubsub tests (#121172) * Improve type hints in google_pubsub tests * Remove from .coveragerc --- .coveragerc | 1 - tests/components/google_pubsub/test_init.py | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.coveragerc b/.coveragerc index 65a4c1bfc31..7980a9c5cdf 100644 --- a/.coveragerc +++ b/.coveragerc @@ -487,7 +487,6 @@ omit = homeassistant/components/goodwe/sensor.py homeassistant/components/google_cloud/tts.py homeassistant/components/google_maps/device_tracker.py - homeassistant/components/google_pubsub/__init__.py homeassistant/components/gpsd/__init__.py homeassistant/components/gpsd/sensor.py homeassistant/components/greenwave/light.py diff --git a/tests/components/google_pubsub/test_init.py b/tests/components/google_pubsub/test_init.py index a793ade5312..d1cc2d88ab0 100644 --- a/tests/components/google_pubsub/test_init.py +++ b/tests/components/google_pubsub/test_init.py @@ -1,9 +1,10 @@ """The tests for the Google Pub/Sub component.""" +from collections.abc import Generator from dataclasses import dataclass from datetime import datetime import os -from unittest import mock +from unittest.mock import MagicMock, Mock, patch import pytest @@ -40,21 +41,21 @@ async def test_nested() -> None: @pytest.fixture(autouse=True, name="mock_client") -def mock_client_fixture(): +def mock_client_fixture() -> Generator[MagicMock]: """Mock the pubsub client.""" - with mock.patch(f"{GOOGLE_PUBSUB_PATH}.PublisherClient") as client: + with patch(f"{GOOGLE_PUBSUB_PATH}.PublisherClient") as client: setattr( client, "from_service_account_json", - mock.MagicMock(return_value=mock.MagicMock()), + MagicMock(return_value=MagicMock()), ) yield client @pytest.fixture(autouse=True, name="mock_is_file") -def mock_is_file_fixture(): +def mock_is_file_fixture() -> Generator[MagicMock]: """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 yield is_file @@ -63,7 +64,7 @@ def mock_is_file_fixture(): def mock_json(hass, monkeypatch): """Mock the event bus listener and os component.""" monkeypatch.setattr( - f"{GOOGLE_PUBSUB_PATH}.json.dumps", mock.Mock(return_value=mock.MagicMock()) + f"{GOOGLE_PUBSUB_PATH}.json.dumps", Mock(return_value=MagicMock()) )