Skip to content

Commit

Permalink
fix: remove test import from tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 14, 2023
1 parent bb28573 commit c529b15
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/test_impl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import socket
from test.test_asyncio import utils as test_utils
from types import ModuleType
from typing import Tuple
from unittest import mock
Expand Down Expand Up @@ -30,11 +29,23 @@ def mock_socket_module():
delattr(m_socket, name)

m_socket.socket = mock.MagicMock()
m_socket.socket.return_value = test_utils.mock_nonblocking_socket()
m_socket.socket.return_value = mock_nonblocking_socket()

return m_socket


def mock_nonblocking_socket(
proto=socket.IPPROTO_TCP, type=socket.SOCK_STREAM, family=socket.AF_INET
):
"""Create a mock of a non-blocking socket."""
sock = mock.create_autospec(socket.socket, spec_set=True, instance=True)
sock.proto = proto
sock.type = type
sock.family = family
sock.gettimeout.return_value = 0.0
return sock


def patch_socket(f):
return mock.patch("aiohappyeyeballs.impl.socket", new_callable=mock_socket_module)(
f
Expand Down

0 comments on commit c529b15

Please sign in to comment.