Skip to content

Commit 5879940

Browse files
committed
feat: add tests for new strip mode
1 parent a2e93d6 commit 5879940

2 files changed

Lines changed: 49 additions & 13 deletions

File tree

tests/conftest.py

Lines changed: 40 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,50 @@ 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("__pycache__/_virtualenv.cpython-313.pyc"),
96+
File.new("project_1.dist-info/RECORD"),
97+
File.new("project_1.dist-info/direct_url.json", contents=json.dumps({"url": str(tmp_path)})),
98+
]
9099
files = [
91100
File.new("project_1/__init__.py"),
92101
File.new("project_1/project1.py"),
102+
File.new("project_1.dist-info/METADATA"),
93103
File.new("small_dependency/__init__.py"),
94104
File.new("small_dependency/small_dependency.py", "# This is a small dependency"),
105+
*files_excluded_from_bundle,
95106
]
96-
data = Data.new(project_name="project-1", project_files=files).commit(loc=tmp_path)
97-
yield data
107+
yield files, files_excluded_from_bundle, tmp_path
98108

99109
@pytest.fixture
100-
def test_data_nested(tmp_path: Path):
110+
def test_files_nested(test_files):
111+
files, files_excluded_from_bundle, tmp_path = test_files
101112
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),
113+
*files,
114+
*[
115+
File.new("gigantic_dependency/__init__.py"),
116+
File.new("gigantic_dependency/gigantic.py", "a" * Packager.AWS_LAMBDA_MAX_UNZIP_SIZE),
117+
],
108118
]
109-
data = Data.new(project_name="project-1", project_files=files).commit(loc=tmp_path)
119+
yield files, files_excluded_from_bundle, tmp_path
120+
121+
@pytest.fixture
122+
def test_data(test_files):
123+
files, files_excluded_from_bundle, loc = test_files
124+
data = Data.new(
125+
project_name="project-1",
126+
project_files=files,
127+
files_excluded_from_bundle=files_excluded_from_bundle,
128+
).commit(loc=loc)
129+
yield data
130+
131+
@pytest.fixture
132+
def test_data_nested(test_files_nested):
133+
files, files_excluded_from_bundle, loc = test_files_nested
134+
data = Data.new(
135+
project_name="project-1-nested",
136+
project_files=files,
137+
files_excluded_from_bundle=files_excluded_from_bundle,
138+
).commit(loc=loc)
110139
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)