Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints to requests_mock #87757

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ClassTypeHintMatch:
"mqtt_mock_entry_with_yaml_config": "MqttMockHAClientGenerator",
"recorder_db_url": "str",
"recorder_mock": "Recorder",
"requests_mock": "requests_mock.Mocker",
}
_TEST_FUNCTION_MATCH = TypeHintMatch(
function_name="test_*",
Expand Down
11 changes: 8 additions & 3 deletions tests/components/darksky/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import forecastio
from requests.exceptions import ConnectionError as ConnectError
import requests_mock

from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -68,7 +69,9 @@
}


async def test_setup_with_config(hass, requests_mock):
async def test_setup_with_config(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None:
"""Test the platform setup with configuration."""
with patch("homeassistant.components.darksky.sensor.forecastio.load_forecast"):
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MINIMAL)
Expand Down Expand Up @@ -106,7 +109,9 @@ async def test_setup_with_invalid_language_config(hass: HomeAssistant) -> None:
assert state is None


async def test_setup_bad_api_key(hass, requests_mock):
async def test_setup_bad_api_key(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None:
"""Test for handling a bad API key."""
# The Dark Sky API wrapper that we use raises an HTTP error
# when you try to use a bad (or no) API key.
Expand Down Expand Up @@ -137,7 +142,7 @@ async def test_connection_error(hass: HomeAssistant) -> None:
assert state is None


async def test_setup(hass, requests_mock):
async def test_setup(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None:
"""Test for successfully setting up the forecast.io platform."""
with patch(
"forecastio.api.get_forecast", wraps=forecastio.api.get_forecast
Expand Down
3 changes: 2 additions & 1 deletion tests/components/darksky/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import forecastio
from requests.exceptions import ConnectionError as ConnectError
import requests_mock

from homeassistant.components import weather
from homeassistant.core import HomeAssistant
Expand All @@ -12,7 +13,7 @@
from tests.common import load_fixture


async def test_setup(hass, requests_mock):
async def test_setup(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None:
"""Test for successfully setting up the forecast.io platform."""
with patch(
"forecastio.api.get_forecast", wraps=forecastio.api.get_forecast
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import multidict
import pytest
import pytest_socket
import requests_mock as _requests_mock
import requests_mock

from homeassistant import core as ha, loader, runner, util
from homeassistant.auth.const import GROUP_ID_ADMIN, GROUP_ID_READ_ONLY
Expand Down Expand Up @@ -490,10 +490,10 @@ def mock_hass():
await event_loop.shutdown_default_executor()


@pytest.fixture
def requests_mock():
@pytest.fixture(name="requests_mock")
def requests_mock_fixture() -> Generator[requests_mock.Mocker, None, None]:
"""Fixture to provide a requests mocker."""
with _requests_mock.mock() as m:
with requests_mock.mock() as m:
yield m


Expand Down