support/testing: add python-httpx2 runtime test
PATCH 1/1 support/testing: add python-httpx2 runtime test
Exercise synchronous and asynchronous HTTP requests with python-httpx2 against a local HTTP server, checking the response status and JSON body. This covers the httpcore2 socket transports and the AnyIO asyncio backend used by the asynchronous client.
Bind the server to an ephemeral loopback port so the test does not depend on external services, and shut it down when the sample finishes.
--- .../tests/package/sample_python_httpx2.py | 37 +++++++++++++++++++ .../tests/package/test_python_httpx2.py | 12 ++++++ 2 files changed, 49 insertions(+) create mode 100644 support/testing/tests/package/sample_python_httpx2.py create mode 100644 support/testing/tests/package/test_python_httpx2.py
support/testing/tests/package/sample_python_httpx2.py new file +37 -0
@@ -0,0 +1,37 @@ +import asyncio +from http.server import BaseHTTPRequestHandler, HTTPServer +from threading import Thread + +import httpx2 + + +class RequestHandler(BaseHTTPRequestHandler): + def do_GET(self): + body = b'{"message": "Hello, Buildroot!"}' + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + +async def test_async(url): + async with httpx2.AsyncClient(trust_env=False) as client: + response = await client.get(url) + assert response.status_code == 200 + assert response.json() == {"message": "Hello, Buildroot!"} + + +with HTTPServer(("127.0.0.1", 0), RequestHandler) as server: + thread = Thread(target=server.serve_forever) + thread.start() + try: + url = f"http://127.0.0.1:{server.server_port}/" + with httpx2.Client(trust_env=False) as client: + response = client.get(url) + assert response.status_code == 200 + assert response.json() == {"message": "Hello, Buildroot!"} + asyncio.run(test_async(url)) + finally: + server.shutdown() + thread.join()
support/testing/tests/package/test_python_httpx2.py new file +12 -0
@@ -0,0 +1,12 @@ +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonPy3Httpx2(TestPythonPackageBase): + __test__ = True + config = TestPythonPackageBase.config + \ + """ + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_HTTPX2=y + """ + sample_scripts = ["tests/package/sample_python_httpx2.py"] + timeout = 30
Signature · 6 lines
2.53.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 9 lines · James Hilliard
Exercise synchronous and asynchronous HTTP requests with python-httpx2 against a local HTTP server, checking the response status and JSON body. This covers the httpcore2 socket transports and the AnyIO asyncio backend used by the asynchronous client.
Bind the server to an ephemeral loopback port so the test does not depend on external services, and shut it down when the sample finishes.
Signed-off-by James Hilliard <[email protected]>
Thanks for this test! You had forgotten to update the DEVELOPERS file, so I did that and applied. Thanks a lot!
Best regards,
Thomas Petazzoni
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot