# Copyright 2019-2021, 2024 Dom Sekotill # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Anyio helpers for unit tests """ from typing import Awaitable from unittest import mock import anyio def _delay_side_effect(delay: float) -> Awaitable[None]: async def coro(*a: object, **k: object) -> None: await anyio.sleep(delay) return coro def patch_connect(delay: float = 0.0) -> mock._patch: return mock.patch( "wpa_supplicant.client.base.connect_unix_datagram", side_effect=_delay_side_effect(delay), ) def patch_send(delay: float = 0.0) -> mock._patch: return mock.patch( "wpa_supplicant.client.base.BaseClient.send_command", side_effect=_delay_side_effect(delay), )