Skip to content
File

Blob: src/workerd/server/tests/python/vendor_dir/worker.py

python43 lines
1import sys
2 
3from a import A
4 
5 
6def test():
7 assert A == 77
8 test_path_ordering()
9 
10 
11def test_path_ordering():
12 """Verify that the Python path is set in the correct order.
13 '/session/metadata/python_modules' should be positioned after the system paths
14 but before any site-packages paths.
15 """
16 python_modules_path = "/session/metadata/python_modules"
17 python_modules_index = sys.path.index(python_modules_path)
18 
19 # Check that vendor_path is in sys.path
20 assert python_modules_index >= 0, f"{python_modules_path} not found in sys.path"
21 
22 # Verify that all site-packages paths come after the vendor path
23 for i, path in enumerate(sys.path):
24 if "site-packages" in path:
25 assert i > python_modules_index, (
26 f"site-packages path {path} appears before python_modules path"
27 )
28 
29 # Verify system paths come before the vendor path
30 system_paths = [
31 "/lib/python312.zip",
32 "/lib/python3.12",
33 "/lib/python3.12/lib-dynload",
34 ]
35 for path in system_paths:
36 if path in sys.path:
37 assert sys.path.index(path) < python_modules_index, (
38 f"System path {path} appears after python_modules path"
39 )
40 
41 # Print the path for debugging if needed
42 print("Python sys.path:", sys.path)