Skip to content

Commit 1077ef7

Browse files
Add missing test for coverage
1 parent 85304cd commit 1077ef7

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

tests/_async/test_http11.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, List
22

33
import pytest
44

@@ -158,6 +158,43 @@ async def test_http11_connection_with_local_protocol_error():
158158
)
159159

160160

161+
@pytest.mark.anyio
162+
async def test_http11_has_expired_checks_readable_status():
163+
class AsyncMockStreamReadable(httpcore.AsyncMockStream):
164+
def __init__(self, buffer: List[bytes]) -> None:
165+
super().__init__(buffer)
166+
self.is_readable = False
167+
self.checks = 0
168+
169+
def get_extra_info(self, info: str) -> Any:
170+
if info == "is_readable":
171+
self.checks += 1
172+
return self.is_readable
173+
return super().get_extra_info(info) # pragma: nocover
174+
175+
origin = httpcore.Origin(b"https", b"example.com", 443)
176+
stream = AsyncMockStreamReadable(
177+
[
178+
b"HTTP/1.1 200 OK\r\n",
179+
b"Content-Type: plain/text\r\n",
180+
b"Content-Length: 13\r\n",
181+
b"\r\n",
182+
b"Hello, world!",
183+
]
184+
)
185+
async with httpcore.AsyncHTTP11Connection(
186+
origin=origin, stream=stream, socket_poll_interval_between=(0, 0)
187+
) as conn:
188+
response = await conn.request("GET", "https://example.com/")
189+
assert response.status == 200
190+
191+
assert stream.checks == 0
192+
assert not conn.has_expired()
193+
stream.is_readable = True
194+
assert conn.has_expired()
195+
assert stream.checks == 2
196+
197+
161198
@pytest.mark.anyio
162199
@pytest.mark.parametrize("should_check", [True, False])
163200
async def test_http11_has_expired_checks_readable_status_by_interval(

tests/_sync/test_http11.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, List
22

33
import pytest
44

@@ -159,6 +159,43 @@ def test_http11_connection_with_local_protocol_error():
159159

160160

161161

162+
def test_http11_has_expired_checks_readable_status():
163+
class MockStreamReadable(httpcore.MockStream):
164+
def __init__(self, buffer: List[bytes]) -> None:
165+
super().__init__(buffer)
166+
self.is_readable = False
167+
self.checks = 0
168+
169+
def get_extra_info(self, info: str) -> Any:
170+
if info == "is_readable":
171+
self.checks += 1
172+
return self.is_readable
173+
return super().get_extra_info(info) # pragma: nocover
174+
175+
origin = httpcore.Origin(b"https", b"example.com", 443)
176+
stream = MockStreamReadable(
177+
[
178+
b"HTTP/1.1 200 OK\r\n",
179+
b"Content-Type: plain/text\r\n",
180+
b"Content-Length: 13\r\n",
181+
b"\r\n",
182+
b"Hello, world!",
183+
]
184+
)
185+
with httpcore.HTTP11Connection(
186+
origin=origin, stream=stream, socket_poll_interval_between=(0, 0)
187+
) as conn:
188+
response = conn.request("GET", "https://example.com/")
189+
assert response.status == 200
190+
191+
assert stream.checks == 0
192+
assert not conn.has_expired()
193+
stream.is_readable = True
194+
assert conn.has_expired()
195+
assert stream.checks == 2
196+
197+
198+
162199
@pytest.mark.parametrize("should_check", [True, False])
163200
def test_http11_has_expired_checks_readable_status_by_interval(
164201
monkeypatch, should_check

0 commit comments

Comments
 (0)