diff --git a/packages/cli/tests/test_in_workerd.py b/packages/cli/tests/test_in_workerd.py index e4cf83a..f47f5fa 100644 --- a/packages/cli/tests/test_in_workerd.py +++ b/packages/cli/tests/test_in_workerd.py @@ -61,7 +61,7 @@ def test_in_workerd( # noqa: PLR0913 (too-many-arguments) # This is reproducible only in the unittest environment, and doesn't happen # when running the same worker manually. if ( - test_dir.name == "sdk" + test_dir.name in ("sdk", "entropy-patches") and compat_date < "2025-09-29" and sys.platform == "linux" ): diff --git a/packages/cli/tests/workerd-test/entropy-patches/entropy-patches.wd-test b/packages/cli/tests/workerd-test/entropy-patches/entropy-patches.wd-test new file mode 100644 index 0000000..7ada6bc --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/entropy-patches.wd-test @@ -0,0 +1,18 @@ +using Workerd = import "/workerd/workerd.capnp"; + +const python :Workerd.Worker = ( + modules = [ + (name = "worker.py", pythonModule = embed "worker.py"), + %PYTHON_MODULES + ], + compatibilityDate = "%COMPAT_DATE", + compatibilityFlags = ["python_workers", "service_binding_extra_handlers", "enable_python_external_sdk", "python_process_pth_files"], +); + +const unitTests :Workerd.Config = ( + services = [ + ( name = "entropy-patches", + worker = .python + ), + ], +); diff --git a/packages/cli/tests/workerd-test/entropy-patches/pyproject.toml b/packages/cli/tests/workerd-test/entropy-patches/pyproject.toml new file mode 100644 index 0000000..f01885a --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "test" +version = "0.0.0" +requires-python = ">=3.12" +dependencies = [ + "pytest", + "pytest-asyncio<1.2.0", + "numpy", + "pydantic", + "requests", + "urllib3", + "tiktoken", + "cryptography", + "jiter", + "aiohttp", + "langsmith", + "langchain-openai", +] diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_aiohttp_websocket.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_aiohttp_websocket.py new file mode 100644 index 0000000..3581cf4 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_aiohttp_websocket.py @@ -0,0 +1,7 @@ +# ruff: noqa: F401 +import aiohttp.http_websocket + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_langsmith.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_langsmith.py new file mode 100644 index 0000000..5f00120 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_langsmith.py @@ -0,0 +1,8 @@ +# ruff: noqa: F401 +import langchain_openai.chat_models.base +import langsmith._internal._constants + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_numpy.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_numpy.py new file mode 100644 index 0000000..20f6de6 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_numpy.py @@ -0,0 +1,9 @@ +# ruff: noqa: F401 +import numpy +import numpy.random +import numpy.random.mtrand + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_pydantic.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_pydantic.py new file mode 100644 index 0000000..64c2bd9 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_pydantic.py @@ -0,0 +1,8 @@ +# ruff: noqa: F401 +import pydantic +import pydantic_core + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_rust_packages.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_rust_packages.py new file mode 100644 index 0000000..bcd522c --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_rust_packages.py @@ -0,0 +1,10 @@ +# ruff: noqa: F401 + +import cryptography.exceptions +import jiter +import tiktoken._tiktoken + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/tests/test_ssl_avoidance.py b/packages/cli/tests/workerd-test/entropy-patches/tests/test_ssl_avoidance.py new file mode 100644 index 0000000..21c9729 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/tests/test_ssl_avoidance.py @@ -0,0 +1,9 @@ +# ruff: noqa: F401 +import aiohttp.connector +import requests.adapters +import urllib3.util.ssl_ + + +def test_import(): + # make sure this file is collected by pytest + pass diff --git a/packages/cli/tests/workerd-test/entropy-patches/worker.py b/packages/cli/tests/workerd-test/entropy-patches/worker.py new file mode 100644 index 0000000..1b0888b --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/worker.py @@ -0,0 +1,26 @@ +import asyncio +import os +import sys + +import pytest +from pyodide.webloop import WebLoop +from workers import WorkerEntrypoint + + +async def noop(*args): + pass + + +# pytest-asyncio relies on these but in Pyodide < 0.29 WebLoop does not implement them +WebLoop.shutdown_asyncgens = noop +WebLoop.shutdown_default_executor = noop + +if sys.version_info < (3, 13): + asyncio.runners._cancel_all_tasks = lambda loop: None # type: ignore[attr-defined] + + +class Default(WorkerEntrypoint): + async def test(self): + os.chdir("/session/metadata/tests") + args = [".", "-vv"] + assert pytest.main(args) == 0 diff --git a/packages/cli/tests/workerd-test/entropy-patches/wrangler.jsonc b/packages/cli/tests/workerd-test/entropy-patches/wrangler.jsonc new file mode 100644 index 0000000..f89cde9 --- /dev/null +++ b/packages/cli/tests/workerd-test/entropy-patches/wrangler.jsonc @@ -0,0 +1,5 @@ +{ + "name": "test-worker", + "compatibility_date": "%COMPAT_DATE", + "compatibility_flags": ["python_workers"] +}