Skip to content

Commit

Permalink
feat: add cover for passing the loop (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 9, 2023
1 parent ae196af commit 2d26911
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions tests/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def patch_socket(f):

@pytest.mark.asyncio
@patch_socket
async def test__single_addr_info_errors(m_socket: ModuleType) -> None:
async def test_single_addr_info_errors(m_socket: ModuleType) -> None:
idx = -1
errors = ["err1", "err2"]

Expand All @@ -68,7 +68,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__single_addr_success(m_socket: ModuleType) -> None:
async def test_single_addr_success(m_socket: ModuleType) -> None:
mock_socket = mock.MagicMock(
family=socket.AF_INET,
type=socket.SOCK_STREAM,
Expand Down Expand Up @@ -96,7 +96,38 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__multiple_addr_success_second_one(
async def test_single_addr_success_passing_loop(m_socket: ModuleType) -> None:
mock_socket = mock.MagicMock(
family=socket.AF_INET,
type=socket.SOCK_STREAM,
proto=socket.IPPROTO_TCP,
fileno=mock.MagicMock(return_value=1),
)

def _socket(*args, **kw):
return mock_socket

m_socket.socket = _socket # type: ignore
addr_info = [
(
socket.AF_INET,
socket.SOCK_STREAM,
socket.IPPROTO_TCP,
"",
("107.6.106.82", 80),
)
]
loop = asyncio.get_running_loop()
with mock.patch.object(loop, "sock_connect", return_value=None):
assert (
await start_connection(addr_info, loop=asyncio.get_running_loop())
== mock_socket
)


@pytest.mark.asyncio
@patch_socket
async def test_multiple_addr_success_second_one(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -139,7 +170,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__multiple_addr_success_second_one_happy_eyeballs(
async def test_multiple_addr_success_second_one_happy_eyeballs(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -184,7 +215,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__multiple_addr_all_fail_happy_eyeballs(
async def test_multiple_addr_all_fail_happy_eyeballs(
m_socket: ModuleType,
) -> None:
mock.MagicMock(
Expand Down Expand Up @@ -225,7 +256,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__ipv6_and_ipv4_happy_eyeballs_ipv6_fails(
async def test_ipv6_and_ipv4_happy_eyeballs_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -268,7 +299,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__ipv6_and_ipv4_happy_eyeballs_ipv4_fails(
async def test_ipv6_and_ipv4_happy_eyeballs_ipv4_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -313,7 +344,7 @@ def _socket(*args, **kw):

@pytest.mark.asyncio
@patch_socket
async def test__ipv6_and_ipv4_happy_eyeballs_first_ipv6_fails(
async def test_ipv6_and_ipv4_happy_eyeballs_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -374,7 +405,7 @@ async def _sock_connect(

@pytest.mark.asyncio
@patch_socket
async def test__ipv64_happy_eyeballs_interleave_2_first_ipv6_fails(
async def test_ipv64_happy_eyeballs_interleave_2_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -437,7 +468,7 @@ async def _sock_connect(

@pytest.mark.asyncio
@patch_socket
async def test__ipv6_only_happy_eyeballs_first_ipv6_fails(
async def test_ipv6_only_happy_eyeballs_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -491,7 +522,7 @@ async def _sock_connect(

@pytest.mark.asyncio
@patch_socket
async def test__ipv64_laddr_eyeballs_interleave_2_first_ipv6_fails(
async def test_ipv64_laddr_eyeballs_interleave_2_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -568,7 +599,7 @@ async def _sock_connect(

@pytest.mark.asyncio
@patch_socket
async def test__ipv64_laddr_both__eyeballs_first_ipv6_fails(
async def test_ipv64_laddr_both__eyeballs_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down Expand Up @@ -650,7 +681,7 @@ async def _sock_connect(

@pytest.mark.asyncio
@patch_socket
async def test__ipv64_laddr_bind_fails_eyeballs_first_ipv6_fails(
async def test_ipv64_laddr_bind_fails_eyeballs_first_ipv6_fails(
m_socket: ModuleType,
) -> None:
mock_socket = mock.MagicMock(
Expand Down

0 comments on commit 2d26911

Please sign in to comment.