Add missing return type in test __init__ methods (#123932)

* Add missing return type in test __init__ methods

* Adjust
This commit is contained in:
epenet 2024-08-14 16:48:52 +02:00 committed by GitHub
parent faacfe3f90
commit 5608301178
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 64 additions and 47 deletions

View File

@ -1,5 +1,6 @@
"""Define patches used for androidtv tests."""
from typing import Any
from unittest.mock import patch
from androidtv.adb_manager.adb_manager_async import DeviceAsync
@ -25,7 +26,7 @@ PROPS_DEV_MAC = "ether ab:cd:ef:gh:ij:kl brd"
class AdbDeviceTcpAsyncFake:
"""A fake of the `adb_shell.adb_device_async.AdbDeviceTcpAsync` class."""
def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize a fake `adb_shell.adb_device_async.AdbDeviceTcpAsync` instance."""
self.available = False

View File

@ -1,5 +1,7 @@
"""Test code shared between test files."""
from typing import Any
from pyatv import conf, const, interface
from pyatv.const import Protocol
@ -7,7 +9,7 @@ from pyatv.const import Protocol
class MockPairingHandler(interface.PairingHandler):
"""Mock for PairingHandler in pyatv."""
def __init__(self, *args):
def __init__(self, *args: Any) -> None:
"""Initialize a new MockPairingHandler."""
super().__init__(*args)
self.pin_code = None

View File

@ -1,6 +1,7 @@
"""Tests for the aws component config and setup."""
import json
from typing import Any
from unittest.mock import AsyncMock, MagicMock, call, patch as async_patch
from homeassistant.core import HomeAssistant
@ -10,7 +11,7 @@ from homeassistant.setup import async_setup_component
class MockAioSession:
"""Mock AioSession."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init a mock session."""
self.get_user = AsyncMock()
self.invoke = AsyncMock()

View File

@ -35,7 +35,7 @@ class AttrDict(dict):
class MockBlackbird:
"""Mock for pyblackbird object."""
def __init__(self):
def __init__(self) -> None:
"""Init mock object."""
self.zones = defaultdict(lambda: AttrDict(power=True, av=1))

View File

@ -271,7 +271,7 @@ async def _async_setup_with_adapter(
class MockBleakClient(BleakClient):
"""Mock bleak client."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Mock init."""
super().__init__(*args, **kwargs)
self._device_path = "/dev/test"

View File

@ -3,6 +3,7 @@
import asyncio
from datetime import timedelta
import time
from typing import Any
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, patch
from bleak import BleakError
@ -100,7 +101,7 @@ async def test_setup_and_stop_passive(
init_kwargs = None
class MockPassiveBleakScanner:
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init the scanner."""
nonlocal init_kwargs
init_kwargs = kwargs
@ -151,7 +152,7 @@ async def test_setup_and_stop_old_bluez(
init_kwargs = None
class MockBleakScanner:
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init the scanner."""
nonlocal init_kwargs
init_kwargs = kwargs

View File

@ -3,6 +3,7 @@
import asyncio
from datetime import timedelta
import time
from typing import Any
from unittest.mock import ANY, MagicMock, patch
from bleak import BleakError
@ -631,7 +632,7 @@ async def test_setup_and_stop_macos(
init_kwargs = None
class MockBleakScanner:
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init the scanner."""
nonlocal init_kwargs
init_kwargs = kwargs

View File

@ -1,6 +1,7 @@
"""Test Bluetooth LE device tracker."""
from datetime import timedelta
from typing import Any
from unittest.mock import patch
from bleak import BleakError
@ -31,7 +32,7 @@ from tests.components.bluetooth import generate_advertisement_data, generate_ble
class MockBleakClient:
"""Mock BleakClient."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Mock BleakClient."""
async def __aenter__(self, *args, **kwargs):

View File

@ -497,7 +497,7 @@ async def test_media_image_proxy(
class MockResponse:
"""Test response."""
def __init__(self):
def __init__(self) -> None:
"""Test response init."""
self.status = 200
self.headers = {"Content-Type": "sometype"}

View File

@ -61,7 +61,7 @@ def async_see(
class MockScannerEntity(ScannerEntity):
"""Test implementation of a ScannerEntity."""
def __init__(self):
def __init__(self) -> None:
"""Init."""
self.connected = False
self._hostname = "test.hostname.org"
@ -110,7 +110,7 @@ class MockScannerEntity(ScannerEntity):
class MockScanner(DeviceScanner):
"""Mock device scanner."""
def __init__(self):
def __init__(self) -> None:
"""Initialize the MockScanner."""
self.devices_home = []

View File

@ -421,7 +421,7 @@ async def _mock_generic_device_entry(
class MockReconnectLogic(BaseMockReconnectLogic):
"""Mock ReconnectLogic."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init the mock."""
super().__init__(*args, **kwargs)
mock_device.set_on_disconnect(kwargs["on_disconnect"])

View File

@ -38,7 +38,7 @@ from tests.common import (
class BaseFan(FanEntity):
"""Implementation of the abstract FanEntity."""
def __init__(self):
def __init__(self) -> None:
"""Initialize the fan."""

View File

@ -3,6 +3,7 @@
from contextlib import contextmanager
from pathlib import Path
from random import getrandbits
from typing import Any
from unittest.mock import patch
import pytest
@ -141,7 +142,7 @@ async def test_upload_large_file_fails(
yield MockPathOpen()
class MockPathOpen:
def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
pass
def write(self, data: bytes) -> None:

View File

@ -427,7 +427,7 @@ async def test_auth_create_token_approval_declined_task_canceled(
class CanceledAwaitableMock(AsyncMock):
"""A canceled awaitable mock."""
def __init__(self):
def __init__(self) -> None:
super().__init__()
self.done = Mock(return_value=False)
self.cancel = Mock()

View File

@ -2,6 +2,7 @@
from collections.abc import AsyncGenerator
import json
from typing import Any
from unittest.mock import AsyncMock, patch
import pypck
@ -29,7 +30,7 @@ class MockModuleConnection(ModuleConnection):
request_name = AsyncMock(return_value="TestModule")
send_command = AsyncMock(return_value=True)
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Construct ModuleConnection instance."""
super().__init__(*args, **kwargs)
self.serials_request_handler.serial_known.set()

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
from contextlib import contextmanager
from typing import Any
from unittest.mock import AsyncMock, MagicMock, Mock, patch
from aiolifx.aiolifx import Light
@ -212,7 +213,7 @@ def _patch_device(device: Light | None = None, no_device: bool = False):
class MockLifxConnecton:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init connection."""
if no_device:
self.device = _mocked_failing_bulb()
@ -240,7 +241,7 @@ def _patch_discovery(device: Light | None = None, no_device: bool = False):
class MockLifxDiscovery:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init discovery."""
if no_device:
self.lights = {}
@ -276,7 +277,7 @@ def _patch_config_flow_try_connect(
class MockLifxConnection:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init connection."""
if no_device:
self.device = _mocked_failing_bulb()

View File

@ -1,5 +1,6 @@
"""Tests for the lifx integration."""
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@ -21,7 +22,7 @@ def mock_effect_conductor():
"""Mock the effect conductor."""
class MockConductor:
def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Mock the conductor."""
self.start = AsyncMock()
self.stop = AsyncMock()

View File

@ -2,6 +2,7 @@
from ipaddress import ip_address
import socket
from typing import Any
from unittest.mock import patch
import pytest
@ -288,7 +289,7 @@ async def test_manual_dns_error(hass: HomeAssistant) -> None:
class MockLifxConnectonDnsError:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init connection."""
self.device = _mocked_failing_bulb()

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import socket
from typing import Any
from unittest.mock import patch
import pytest
@ -37,7 +38,7 @@ async def test_configuring_lifx_causes_discovery(hass: HomeAssistant) -> None:
class MockLifxDiscovery:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init discovery."""
discovered = _mocked_bulb()
self.lights = {discovered.mac_addr: discovered}
@ -137,7 +138,7 @@ async def test_dns_error_at_startup(hass: HomeAssistant) -> None:
class MockLifxConnectonDnsError:
"""Mock lifx connection with a dns error."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init connection."""
self.device = bulb

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import patch
from homeassistant import setup
@ -114,7 +115,7 @@ async def test_discovery_is_more_frequent_during_migration(
class MockLifxDiscovery:
"""Mock lifx discovery."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init discovery."""
self.bulb = bulb
self.lights = {}

View File

@ -58,7 +58,7 @@ class AttrDict(dict):
class MockMonoprice:
"""Mock for pymonoprice object."""
def __init__(self):
def __init__(self) -> None:
"""Init mock object."""
self.zones = defaultdict(
lambda: AttrDict(power=True, volume=0, mute=True, source=1)

View File

@ -92,7 +92,7 @@ class FakeSubscriber(GoogleNestSubscriber):
stop_calls = 0
def __init__(self): # pylint: disable=super-init-not-called
def __init__(self) -> None: # pylint: disable=super-init-not-called
"""Initialize Fake Subscriber."""
self._device_manager = DeviceManager()

View File

@ -53,7 +53,7 @@ class FakeAuth(AbstractAuth):
from the API.
"""
def __init__(self):
def __init__(self) -> None:
"""Initialize FakeAuth."""
super().__init__(None, None)
# Tests can set fake responses here.

View File

@ -8,7 +8,7 @@ class NumatoModuleMock:
NumatoGpioError = NumatoGpioError
def __init__(self):
def __init__(self) -> None:
"""Initialize the numato_gpio module mockup class."""
self.devices = {}

View File

@ -121,7 +121,7 @@ class MockNumberEntityDescr(NumberEntity):
Step is calculated based on the smaller max_value and min_value.
"""
def __init__(self):
def __init__(self) -> None:
"""Initialize the clas instance."""
self.entity_description = NumberEntityDescription(
"test",
@ -145,7 +145,7 @@ class MockNumberEntityAttrWithDescription(NumberEntity):
members take precedence over the entity description.
"""
def __init__(self):
def __init__(self) -> None:
"""Initialize the clas instance."""
self.entity_description = NumberEntityDescription(
"test",
@ -223,7 +223,7 @@ class MockNumberEntityDescrDeprecated(NumberEntity):
Step is calculated based on the smaller max_value and min_value.
"""
def __init__(self):
def __init__(self) -> None:
"""Initialize the clas instance."""
self.entity_description = NumberEntityDescription(
"test",

View File

@ -1,6 +1,7 @@
"""OralB session fixtures."""
from collections.abc import Generator
from typing import Any
from unittest import mock
import pytest
@ -19,7 +20,7 @@ class MockBleakClient:
services = MockServices()
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Mock BleakClient."""
async def __aenter__(self, *args, **kwargs):

View File

@ -537,7 +537,7 @@ async def test_manual_config(hass: HomeAssistant, mock_plex_calls) -> None:
class WrongCertValidaitionException(requests.exceptions.SSLError):
"""Mock the exception showing an unmatched error."""
def __init__(self): # pylint: disable=super-init-not-called
def __init__(self) -> None: # pylint: disable=super-init-not-called
self.__context__ = ssl.SSLCertVerificationError(
"some random message that doesn't match"
)

View File

@ -209,7 +209,7 @@ async def test_setup_when_certificate_changed(
class WrongCertHostnameException(requests.exceptions.SSLError):
"""Mock the exception showing a mismatched hostname."""
def __init__(self): # pylint: disable=super-init-not-called
def __init__(self) -> None: # pylint: disable=super-init-not-called
self.__context__ = ssl.SSLCertVerificationError(
f"hostname '{old_domain}' doesn't match"
)

View File

@ -284,14 +284,14 @@ async def test_lru_stats(hass: HomeAssistant, caplog: pytest.LogCaptureFixture)
return 1
class DomainData:
def __init__(self):
def __init__(self) -> None:
self._data = LRU(1)
domain_data = DomainData()
assert hass.services.has_service(DOMAIN, SERVICE_LRU_STATS)
class LRUCache:
def __init__(self):
def __init__(self) -> None:
self._data = {"sqlalchemy_test": 1}
sqlalchemy_lru_cache = LRUCache()

View File

@ -16,6 +16,7 @@ import asyncio
from collections.abc import Generator
import logging
import threading
from typing import Any
from unittest.mock import Mock, patch
from aiohttp import web
@ -32,7 +33,7 @@ TEST_TIMEOUT = 7.0 # Lower than 9s home assistant timeout
class WorkerSync:
"""Test fixture that intercepts stream worker calls to StreamOutput."""
def __init__(self):
def __init__(self) -> None:
"""Initialize WorkerSync."""
self._event = None
self._original = StreamState.discontinuity
@ -74,7 +75,7 @@ def stream_worker_sync() -> Generator[WorkerSync]:
class HLSSync:
"""Test fixture that intercepts stream worker calls to StreamOutput."""
def __init__(self):
def __init__(self) -> None:
"""Initialize HLSSync."""
self._request_event = asyncio.Event()
self._original_recv = StreamOutput.recv
@ -91,7 +92,7 @@ class HLSSync:
self.check_requests_ready()
class SyncResponse(web.Response):
def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
on_resp()

View File

@ -160,7 +160,7 @@ class PacketSequence:
class FakePacket(bytearray):
# Be a bytearray so that memoryview works
def __init__(self):
def __init__(self) -> None:
super().__init__(3)
time_base = VIDEO_TIME_BASE
@ -209,7 +209,7 @@ class FakePyAvContainer:
class FakePyAvBuffer:
"""Holds outputs of the decoded stream for tests to assert on results."""
def __init__(self):
def __init__(self) -> None:
"""Initialize the FakePyAvBuffer."""
self.segments = []
self.audio_packets = []

View File

@ -920,7 +920,7 @@ async def test_subscribe_entities_with_unserializable_state(
class CannotSerializeMe:
"""Cannot serialize this."""
def __init__(self):
def __init__(self) -> None:
"""Init cannot serialize this."""
hass.states.async_set("light.permitted", "off", {"color": "red"})

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from collections.abc import Generator
from datetime import datetime
from typing import Any
from unittest.mock import AsyncMock, MagicMock, Mock, patch
import pytest
@ -74,7 +75,7 @@ def mock_whois_missing_some_attrs() -> Generator[Mock]:
class LimitedWhoisMock:
"""A limited mock of whois_query."""
def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Mock only attributes the library always sets being available."""
self.creation_date = datetime(2019, 1, 1, 0, 0, 0)
self.dnssec = True

View File

@ -19,7 +19,7 @@ class MockBleakClient:
services = MockServices()
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
"""Mock BleakClient."""
async def __aenter__(self, *args, **kwargs):

View File

@ -37,7 +37,7 @@ def mock_stream(data):
class AiohttpClientMocker:
"""Mock Aiohttp client requests."""
def __init__(self):
def __init__(self) -> None:
"""Initialize the request mocker."""
self._mocks = []
self._cookies = {}
@ -327,7 +327,7 @@ class MockLongPollSideEffect:
If queue is empty, will await until done.
"""
def __init__(self):
def __init__(self) -> None:
"""Initialize the queue."""
self.semaphore = asyncio.Semaphore(0)
self.response_list = []