Skip to content

Commit

Permalink
test(build): order in RECORD files and archives should be determinist…
Browse files Browse the repository at this point in the history
…ic due to python-poetry#545
  • Loading branch information
radoering committed Mar 11, 2023
1 parent 7976f68 commit accd3fc
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def test_wheel_c_extension(project: str, exptected_c_dir: str) -> None:
assert re.search(r"\s+extended/extended.*\.(so|pyd)", record) is not None

# Files in RECORD should match files in wheel.
zip_files = sorted(zipf.namelist())
assert zip_files == sorted(record_files)
assert zipf.namelist() == record_files
assert len(set(record_files)) == len(record_files)


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

expected_name_list = [
"my_package/__init__.py",
"my_package/data1/test.json",
"my_package/sub_pkg1/__init__.py",
"my_package/sub_pkg2/__init__.py",
"my_package/sub_pkg2/data2/data.json",
"my_package-1.2.3.data/scripts/script.sh",
"my_package/sub_pkg3/foo.py",
"my_package-1.2.3.dist-info/entry_points.txt",
"my_package-1.2.3.dist-info/LICENSE",
"my_package-1.2.3.dist-info/WHEEL",
"my_package-1.2.3.dist-info/METADATA",
"my_package-1.2.3.dist-info/RECORD",
]
expected_name_list = (
[
"my_package/__init__.py",
"my_package/data1/test.json",
"my_package/sub_pkg1/__init__.py",
"my_package/sub_pkg2/__init__.py",
"my_package/sub_pkg2/data2/data.json",
"my_package/sub_pkg3/foo.py",
"my_package-1.2.3.data/scripts/script.sh",
]
+ sorted(
[
"my_package-1.2.3.dist-info/entry_points.txt",
"my_package-1.2.3.dist-info/LICENSE",
"my_package-1.2.3.dist-info/METADATA",
"my_package-1.2.3.dist-info/WHEEL",
],
key=lambda x: Path(x),
)
+ ["my_package-1.2.3.dist-info/RECORD"]
)

with zipfile.ZipFile(str(whl)) as zipf:
assert sorted(zipf.namelist()) == sorted(expected_name_list)
assert zipf.namelist() == expected_name_list
assert (
"Hello World"
in zipf.read("my_package-1.2.3.data/scripts/script.sh").decode()
Expand Down Expand Up @@ -208,12 +214,11 @@ def test_complete(no_vcs: bool) -> None:
)
actual_records = zipf.read("my_package-1.2.3.dist-info/RECORD").decode()

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

assert sorted(actual_files) == sorted(expected_name_list)
assert actual_files == expected_name_list


def test_module_src() -> None:
Expand Down

0 comments on commit accd3fc

Please sign in to comment.