Skip to content

Commit 35e656c

Browse files
committed
test(build): order in RECORD files and archives should be deterministic due to #545
1 parent f598e81 commit 35e656c

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

tests/masonry/builders/test_complete.py

+25-20
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def test_wheel_c_extension(project: str, exptected_c_dir: str) -> None:
9595
assert re.search(r"\s+extended/extended.*\.(so|pyd)", record) is not None
9696

9797
# Files in RECORD should match files in wheel.
98-
zip_files = sorted(zipf.namelist())
99-
assert zip_files == sorted(record_files)
98+
assert zipf.namelist() == record_files
10099
assert len(set(record_files)) == len(record_files)
101100

102101

@@ -119,23 +118,30 @@ def test_complete(no_vcs: bool) -> None:
119118
if sys.platform != "win32":
120119
assert (os.stat(str(whl)).st_mode & 0o777) == 0o644
121120

122-
expected_name_list = [
123-
"my_package/__init__.py",
124-
"my_package/data1/test.json",
125-
"my_package/sub_pkg1/__init__.py",
126-
"my_package/sub_pkg2/__init__.py",
127-
"my_package/sub_pkg2/data2/data.json",
128-
"my_package-1.2.3.data/scripts/script.sh",
129-
"my_package/sub_pkg3/foo.py",
130-
"my_package-1.2.3.dist-info/entry_points.txt",
131-
"my_package-1.2.3.dist-info/LICENSE",
132-
"my_package-1.2.3.dist-info/WHEEL",
133-
"my_package-1.2.3.dist-info/METADATA",
134-
"my_package-1.2.3.dist-info/RECORD",
135-
]
121+
expected_name_list = (
122+
[
123+
"my_package/__init__.py",
124+
"my_package/data1/test.json",
125+
"my_package/sub_pkg1/__init__.py",
126+
"my_package/sub_pkg2/__init__.py",
127+
"my_package/sub_pkg2/data2/data.json",
128+
"my_package/sub_pkg3/foo.py",
129+
"my_package-1.2.3.data/scripts/script.sh",
130+
]
131+
+ sorted(
132+
[
133+
"my_package-1.2.3.dist-info/entry_points.txt",
134+
"my_package-1.2.3.dist-info/LICENSE",
135+
"my_package-1.2.3.dist-info/METADATA",
136+
"my_package-1.2.3.dist-info/WHEEL",
137+
],
138+
key=lambda x: Path(x),
139+
)
140+
+ ["my_package-1.2.3.dist-info/RECORD"]
141+
)
136142

137143
with zipfile.ZipFile(str(whl)) as zipf:
138-
assert sorted(zipf.namelist()) == sorted(expected_name_list)
144+
assert zipf.namelist() == expected_name_list
139145
assert (
140146
"Hello World"
141147
in zipf.read("my_package-1.2.3.data/scripts/script.sh").decode()
@@ -208,12 +214,11 @@ def test_complete(no_vcs: bool) -> None:
208214
)
209215
actual_records = zipf.read("my_package-1.2.3.dist-info/RECORD").decode()
210216

211-
# For some reason, the ordering of the files and the SHA hashes
212-
# vary per operating systems and Python versions.
217+
# The SHA hashes vary per operating systems.
213218
# So instead of 1:1 assertion, let's do a bit clunkier one:
214219
actual_files = [row[0] for row in csv.reader(actual_records.splitlines())]
215220

216-
assert sorted(actual_files) == sorted(expected_name_list)
221+
assert actual_files == expected_name_list
217222

218223

219224
def test_module_src() -> None:

0 commit comments

Comments
 (0)