Remove async magic patch from tests (#1146)

Not required since AsyncMock available in python 3.8 and probably better
to keep magic to a minimum.
This commit is contained in:
Steven B.
2024-10-02 16:12:10 +01:00
committed by GitHub
parent 1026e890a1
commit 8bb2cca7cf
4 changed files with 19 additions and 18 deletions

View File

@@ -9,6 +9,7 @@ import pkgutil
import struct
import sys
from typing import cast
from unittest.mock import AsyncMock
import pytest
@@ -175,6 +176,7 @@ async def test_protocol_reconnect(
writer = mocker.patch("asyncio.StreamWriter")
mocker.patch.object(writer, "write", _fail_one_less_than_retry_count)
mocker.patch.object(reader, "readexactly", _mock_read)
mocker.patch.object(writer, "drain", new_callable=AsyncMock)
return reader, writer
config = DeviceConfig("127.0.0.1")
@@ -224,6 +226,7 @@ async def test_protocol_handles_cancellation_during_write(
writer = mocker.patch("asyncio.StreamWriter")
mocker.patch.object(writer, "write", _cancel_first_attempt)
mocker.patch.object(reader, "readexactly", _mock_read)
mocker.patch.object(writer, "drain", new_callable=AsyncMock)
return reader, writer
config = DeviceConfig("127.0.0.1")
@@ -275,6 +278,7 @@ async def test_protocol_handles_cancellation_during_connection(
reader = mocker.patch("asyncio.StreamReader")
writer = mocker.patch("asyncio.StreamWriter")
mocker.patch.object(reader, "readexactly", _mock_read)
mocker.patch.object(writer, "drain", new_callable=AsyncMock)
return reader, writer
config = DeviceConfig("127.0.0.1")
@@ -324,6 +328,7 @@ async def test_protocol_logging(
reader = mocker.patch("asyncio.StreamReader")
writer = mocker.patch("asyncio.StreamWriter")
mocker.patch.object(reader, "readexactly", _mock_read)
mocker.patch.object(writer, "drain", new_callable=AsyncMock)
return reader, writer
config = DeviceConfig("127.0.0.1")
@@ -373,6 +378,7 @@ async def test_protocol_custom_port(
else:
assert port == custom_port
mocker.patch.object(reader, "readexactly", _mock_read)
mocker.patch.object(writer, "drain", new_callable=AsyncMock)
return reader, writer
config = DeviceConfig("127.0.0.1", port_override=custom_port)