From 85b10c38f39732421a230d938adddc7805d0e001 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 16 Nov 2026 09:27:29 +0100 Subject: style(core): reorder module declarations Group globals and data classes near module imports, keep primary classes and functions together, and move implementation helpers after their public callers. Reorder Alembic setup so configuration happens after the required helpers are defined, without changing runtime behavior. --- tests/test_net.py | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'tests/test_net.py') diff --git a/tests/test_net.py b/tests/test_net.py index 24785ee..472ae91 100644 --- a/tests/test_net.py +++ b/tests/test_net.py @@ -31,6 +31,37 @@ from webmentions_ssg.net import ( ) +class FakeStream(httpcore.NetworkStream): + """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" + + def __init__(self, response: bytes) -> None: + self.response = response + self.writes = bytearray() + self.sni: str | None = None + + def read(self, max_bytes: int, timeout: float | None = None) -> bytes: + part, self.response = self.response[:max_bytes], self.response[max_bytes:] + return part + + def write(self, buffer: bytes, timeout: float | None = None) -> None: + self.writes.extend(buffer) + + def start_tls( + self, + ssl_context, + server_hostname: str | None = None, + timeout: float | None = None, + ) -> httpcore.NetworkStream: + self.sni = server_hostname + return self + + def get_extra_info(self, info: str): + return None + + def close(self) -> None: + pass + + @pytest.mark.parametrize("host", ["127.0.0.1", "169.254.169.254", "::1"]) def test_backend_rejects_private_ip_without_socket( monkeypatch: pytest.MonkeyPatch, host: str @@ -125,37 +156,6 @@ def test_read_limited_body_raises_specific_size_error(mode: str) -> None: read_limited_body(response, 10, label="Source") -class FakeStream(httpcore.NetworkStream): - """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" - - def __init__(self, response: bytes) -> None: - self.response = response - self.writes = bytearray() - self.sni: str | None = None - - def read(self, max_bytes: int, timeout: float | None = None) -> bytes: - part, self.response = self.response[:max_bytes], self.response[max_bytes:] - return part - - def write(self, buffer: bytes, timeout: float | None = None) -> None: - self.writes.extend(buffer) - - def start_tls( - self, - ssl_context, - server_hostname: str | None = None, - timeout: float | None = None, - ) -> httpcore.NetworkStream: - self.sni = server_hostname - return self - - def get_extra_info(self, info: str): - return None - - def close(self) -> None: - pass - - @pytest.mark.parametrize("scheme", ["http", "https"]) def test_transport_keeps_original_http_host_and_tls_sni( monkeypatch: pytest.MonkeyPatch, scheme: str -- cgit v1.3.1