Skip to content

Commit bbf4e80

Browse files
committed
feat: add tests for new strip mode
1 parent c4163fe commit bbf4e80

2 files changed

Lines changed: 48 additions & 13 deletions

File tree

tests/conftest.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from dataclasses import dataclass
23
from pathlib import Path
34
from typing import Self
@@ -24,6 +25,7 @@ def new(cls, path: str, contents: str = "") -> Self:
2425

2526
@dataclass
2627
class Data:
28+
files_excluded_from_bundle: list[File] # relative to packages_dir
2729
project_files: list[File] # relative to packages_dir
2830
pyproject: PythonProject
2931
python_version: str
@@ -34,10 +36,12 @@ def new(
3436
cls,
3537
project_name: str,
3638
project_files: list[File],
39+
files_excluded_from_bundle: list[File],
3740
python_version: str = "3.13",
3841
) -> Self:
3942
pyproject = _new_python_project(name=project_name)
4043
return cls(
44+
files_excluded_from_bundle=files_excluded_from_bundle,
4145
project_files=project_files,
4246
pyproject=pyproject,
4347
python_version=python_version,
@@ -86,25 +90,49 @@ def verify_file_reproducibility(file_info: list[ZipInfo], expected_file_date_tim
8690
assert info.date_time == expected_file_date_time
8791

8892
@pytest.fixture
89-
def test_data(tmp_path: Path):
93+
def test_files(tmp_path: Path):
94+
files_excluded_from_bundle = [
95+
File.new("project_1.dist-info/RECORD"),
96+
File.new("project_1.dist-info/direct_url.json", contents=json.dumps({"url": str(tmp_path)})),
97+
]
9098
files = [
9199
File.new("project_1/__init__.py"),
92100
File.new("project_1/project1.py"),
101+
File.new("project_1.dist-info/METADATA"),
93102
File.new("small_dependency/__init__.py"),
94103
File.new("small_dependency/small_dependency.py", "# This is a small dependency"),
104+
*files_excluded_from_bundle,
95105
]
96-
data = Data.new(project_name="project-1", project_files=files).commit(loc=tmp_path)
97-
yield data
106+
yield files, files_excluded_from_bundle, tmp_path
98107

99108
@pytest.fixture
100-
def test_data_nested(tmp_path: Path):
109+
def test_files_nested(test_files):
110+
files, files_excluded_from_bundle, tmp_path = test_files
101111
files = [
102-
File.new("project_1/__init__.py"),
103-
File.new("project_1/project1.py"),
104-
File.new("small_dependency/__init__.py"),
105-
File.new("small_dependency/small_dependency.py", "# This is a small dependency"),
106-
File.new("gigantic_dependency/__init__.py"),
107-
File.new("gigantic_dependency/gigantic.py", "a" * Packager.AWS_LAMBDA_MAX_UNZIP_SIZE),
112+
*files,
113+
*[
114+
File.new("gigantic_dependency/__init__.py"),
115+
File.new("gigantic_dependency/gigantic.py", "a" * Packager.AWS_LAMBDA_MAX_UNZIP_SIZE),
116+
],
108117
]
109-
data = Data.new(project_name="project-1", project_files=files).commit(loc=tmp_path)
118+
yield files, files_excluded_from_bundle, tmp_path
119+
120+
@pytest.fixture
121+
def test_data(test_files):
122+
files, files_excluded_from_bundle, loc = test_files
123+
data = Data.new(
124+
project_name="project-1",
125+
project_files=files,
126+
files_excluded_from_bundle=files_excluded_from_bundle,
127+
).commit(loc=loc)
128+
yield data
129+
130+
@pytest.fixture
131+
def test_data_nested(test_files_nested):
132+
files, files_excluded_from_bundle, loc = test_files_nested
133+
data = Data.new(
134+
project_name="project-1-nested",
135+
project_files=files,
136+
files_excluded_from_bundle=files_excluded_from_bundle,
137+
).commit(loc=loc)
110138
yield data

tests/test_package_python_function.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def test_package_python_function(
6767
verify_file_reproducibility(zip.infolist(), expected_file_date_time=expected_date_time)
6868

6969
for file in test_data.project_files:
70-
assert (verify_dir / file.path).exists()
70+
if file in test_data.files_excluded_from_bundle:
71+
assert not (verify_dir / file.path).exists()
72+
else:
73+
assert (verify_dir / file.path).exists()
7174

7275
@pytest.mark.parametrize(
7376
"src_epoch, expected_exception, expected_date_time",
@@ -131,5 +134,9 @@ def test_package_python_function_nested(
131134
with zipfile.ZipFile(inner_zip, "r") as izip:
132135
izip.extractall(verify_dir)
133136
verify_file_reproducibility(izip.infolist(), expected_file_date_time=expected_date_time)
137+
134138
for file in test_data_nested.project_files:
135-
assert (verify_dir / file.path).exists()
139+
if file in test_data_nested.files_excluded_from_bundle:
140+
assert not (verify_dir / file.path).exists()
141+
else:
142+
assert (verify_dir / file.path).exists()

0 commit comments

Comments
 (0)