1414from build_lambda_layer import BuildConfig , build_layer
1515
1616
17- def test_build_layer_installs_dependencies_and_zips_lambda_layout (
17+ def _write_test_wheel (
18+ directory : Path ,
19+ distribution : str ,
20+ package_files : tuple [str , ...],
21+ dependencies : tuple [str , ...] = (),
22+ ) -> Path :
23+ normalized_distribution = distribution .replace ("-" , "_" )
24+ wheel = directory / f"{ normalized_distribution } -1.0.0-py3-none-any.whl"
25+ dist_info = f"{ normalized_distribution } -1.0.0.dist-info"
26+ metadata = [
27+ "Metadata-Version: 2.1" ,
28+ f"Name: { distribution } " ,
29+ "Version: 1.0.0" ,
30+ * (f"Requires-Dist: { dependency } ==1.0.0" for dependency in dependencies ),
31+ "" ,
32+ ]
33+
34+ with zipfile .ZipFile (wheel , "w" ) as archive :
35+ for package_file in package_files :
36+ archive .writestr (package_file , "" )
37+ archive .writestr (f"{ dist_info } /METADATA" , "\n " .join (metadata ))
38+ archive .writestr (
39+ f"{ dist_info } /WHEEL" ,
40+ "\n " .join (
41+ (
42+ "Wheel-Version: 1.0" ,
43+ "Generator: test" ,
44+ "Root-Is-Purelib: true" ,
45+ "Tag: py3-none-any" ,
46+ "" ,
47+ )
48+ ),
49+ )
50+ archive .writestr (f"{ dist_info } /RECORD" , "" )
51+
52+ return wheel
53+
54+
55+ def test_build_layer_installs_distributions_and_zips_lambda_layout (
1856 monkeypatch : pytest .MonkeyPatch ,
1957 tmp_path : Path ,
2058) -> None :
@@ -42,17 +80,17 @@ def fake_run(command: list[str], check: bool) -> subprocess.CompletedProcess[str
4280 output = build_layer (
4381 BuildConfig (
4482 output = tmp_path / "layer.zip" ,
45- target_python = "3.12" ,
46- architecture = "arm64" ,
4783 sdk_distribution = sdk_wheel ,
4884 otel_distribution = otel_wheel ,
4985 )
5086 )
5187
5288 assert output == tmp_path / "layer.zip"
53- assert commands [0 ][commands [0 ].index ("--platform" ) + 1 ] == "manylinux2014_aarch64"
54- assert commands [0 ][commands [0 ].index ("--abi" ) + 1 ] == "cp312"
5589 assert "--no-compile" in commands [0 ]
90+ assert "--no-deps" in commands [0 ]
91+ assert "--platform" not in commands [0 ]
92+ assert "--python-version" not in commands [0 ]
93+ assert "--abi" not in commands [0 ]
5694 assert str (sdk_wheel ) in commands [0 ]
5795 assert str (otel_wheel ) in commands [0 ]
5896
@@ -66,52 +104,84 @@ def fake_run(command: list[str], check: bool) -> subprocess.CompletedProcess[str
66104 )
67105
68106
69- @pytest .mark .parametrize (
70- ("target_python" , "architecture" , "error" ),
71- [
72- ("3.10" , "x86_64" , "Unsupported Python version" ),
73- ("3.12" , "sparc" , "Unsupported architecture" ),
74- ],
75- )
76- def test_build_layer_rejects_unsupported_targets (
77- target_python : str ,
78- architecture : str ,
79- error : str ,
107+ def test_build_layer_excludes_adot_and_runtime_dependencies (
108+ monkeypatch : pytest .MonkeyPatch ,
80109 tmp_path : Path ,
81110) -> None :
82- sdk_wheel = tmp_path / "sdk.whl"
83- otel_wheel = tmp_path / "otel.whl"
84- sdk_wheel .write_text ("sdk" )
85- otel_wheel .write_text ("otel" )
111+ sdk_wheel = _write_test_wheel (
112+ tmp_path ,
113+ "aws-durable-execution-sdk-python" ,
114+ ("aws_durable_execution_sdk_python/__init__.py" ,),
115+ ("boto3" ,),
116+ )
117+ otel_wheel = _write_test_wheel (
118+ tmp_path ,
119+ "aws-durable-execution-sdk-python-otel" ,
120+ ("aws_durable_execution_sdk_python_otel/__init__.py" ,),
121+ ("aws-opentelemetry-distro" , "opentelemetry-api" ),
122+ )
123+ _write_test_wheel (tmp_path , "boto3" , ("boto3/__init__.py" ,))
124+ _write_test_wheel (
125+ tmp_path ,
126+ "aws-opentelemetry-distro" ,
127+ ("amazon/opentelemetry/distro/__init__.py" ,),
128+ )
129+ _write_test_wheel (
130+ tmp_path ,
131+ "opentelemetry-api" ,
132+ ("opentelemetry/__init__.py" ,),
133+ )
134+ monkeypatch .setenv ("PIP_FIND_LINKS" , str (tmp_path ))
135+ monkeypatch .setenv ("PIP_NO_INDEX" , "1" )
86136
87- with pytest .raises (ValueError , match = error ):
88- build_layer (
89- BuildConfig (
90- output = tmp_path / "layer.zip" ,
91- target_python = target_python ,
92- architecture = architecture ,
93- sdk_distribution = sdk_wheel ,
94- otel_distribution = otel_wheel ,
95- )
137+ output = build_layer (
138+ BuildConfig (
139+ output = tmp_path / "layer.zip" ,
140+ sdk_distribution = sdk_wheel ,
141+ otel_distribution = otel_wheel ,
96142 )
143+ )
144+
145+ with zipfile .ZipFile (output ) as archive :
146+ names = archive .namelist ()
147+
148+ assert "python/aws_durable_execution_sdk_python/__init__.py" in names
149+ assert "python/aws_durable_execution_sdk_python_otel/__init__.py" in names
150+ assert not any (name .startswith ("python/amazon/" ) for name in names )
151+ assert not any (name .startswith ("python/boto3/" ) for name in names )
152+ assert not any (name .startswith ("python/opentelemetry/" ) for name in names )
97153
98154
99155def test_build_layer_requires_built_distributions (tmp_path : Path ) -> None :
100156 with pytest .raises (FileNotFoundError ):
101157 build_layer (
102158 BuildConfig (
103159 output = tmp_path / "layer.zip" ,
104- target_python = "3.13" ,
105- architecture = "x86_64" ,
106160 sdk_distribution = tmp_path / "missing-sdk.whl" ,
107161 otel_distribution = tmp_path / "missing-otel.whl" ,
108162 )
109163 )
110164
111165
166+ def test_build_layer_requires_universal_wheels (tmp_path : Path ) -> None :
167+ sdk_wheel = tmp_path / "sdk-1.0.0-cp311-cp311-manylinux2014_x86_64.whl"
168+ otel_wheel = tmp_path / "otel-1.0.0-py3-none-any.whl"
169+ sdk_wheel .write_text ("sdk" )
170+ otel_wheel .write_text ("otel" )
171+
172+ with pytest .raises (ValueError , match = "must be universal wheels" ):
173+ build_layer (
174+ BuildConfig (
175+ output = tmp_path / "layer.zip" ,
176+ sdk_distribution = sdk_wheel ,
177+ otel_distribution = otel_wheel ,
178+ )
179+ )
180+
181+
112182def test_build_layer_rejects_output_inside_build_directory (tmp_path : Path ) -> None :
113- sdk_wheel = tmp_path / "sdk.whl"
114- otel_wheel = tmp_path / "otel.whl"
183+ sdk_wheel = tmp_path / "sdk-1.0.0-py3-none-any .whl"
184+ otel_wheel = tmp_path / "otel-1.0.0-py3-none-any .whl"
115185 sdk_wheel .write_text ("sdk" )
116186 otel_wheel .write_text ("otel" )
117187 build_dir = tmp_path / "layer"
@@ -120,8 +190,6 @@ def test_build_layer_rejects_output_inside_build_directory(tmp_path: Path) -> No
120190 build_layer (
121191 BuildConfig (
122192 output = build_dir / "layer.zip" ,
123- target_python = "3.13" ,
124- architecture = "x86_64" ,
125193 sdk_distribution = sdk_wheel ,
126194 otel_distribution = otel_wheel ,
127195 build_dir = build_dir ,
0 commit comments