Skip to content

Commit 5389674

Browse files
authored
tests: reproducible on Python < 3.9 (just different) (#66)
- tests: tarfile on older Pythons was different. - tests: adding failing test for wheel Signed-off-by: Henry Schreiner <[email protected]>
1 parent e20e96f commit 5389674

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

tests/test_pyproject_pep517.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"""
3333

3434
mark_hashes_different = pytest.mark.xfail(
35-
sys.version_info < (3, 9) or sys.platform.startswith("win32"),
36-
reason="hashes differ on Windows and Python < 3.9",
35+
sys.platform.startswith("win32"),
36+
reason="hashes differ on Windows",
3737
)
3838

3939

@@ -75,7 +75,14 @@ def test_pep517_sdist_hash(tmp_path, monkeypatch):
7575
out = build_sdist(str(dist))
7676
sdist = dist / out
7777
hash = hashlib.sha256(sdist.read_bytes()).hexdigest()
78-
assert hash == "03455cc6996c1d0d4977bedb611180cf561ade9d70d7b5d1216a40405adf7b47"
78+
if sys.version_info < (3, 9):
79+
assert (
80+
hash == "09b0593a80d0b0c086fddb99378e6dc75ba50e041076cd4a9a7afe4053407362"
81+
)
82+
else:
83+
assert (
84+
hash == "03455cc6996c1d0d4977bedb611180cf561ade9d70d7b5d1216a40405adf7b47"
85+
)
7986

8087

8188
def test_pep517_sdist_time_hash(tmp_path, monkeypatch):
@@ -136,7 +143,14 @@ def test_pep517_sdist_time_hash_set_epoch(tmp_path, monkeypatch):
136143
out = build_sdist(str(dist), {"scikit-build-core.sdist.reproducible": "false"})
137144
sdist = dist / out
138145
hash = hashlib.sha256(sdist.read_bytes()).hexdigest()
139-
assert hash == "a39a0eecb02f7b583ab3008c0c64c55eaef9d0bb5e712b6cb8d469598771ddfb"
146+
if sys.version_info < (3, 9):
147+
assert (
148+
hash == "7656ce7df4c1d6bbd098f046f75bb610104260542de5eeaf40993bb2976bf34e"
149+
)
150+
else:
151+
assert (
152+
hash == "a39a0eecb02f7b583ab3008c0c64c55eaef9d0bb5e712b6cb8d469598771ddfb"
153+
)
140154

141155

142156
@pytest.mark.compile
@@ -189,3 +203,31 @@ def test_pep517_wheel(tmp_path, monkeypatch, virtualenv):
189203
capture=True,
190204
)
191205
assert add.strip() == "3"
206+
207+
208+
@pytest.mark.skip(reason="Doesn't work yet")
209+
@pytest.mark.compile
210+
@pytest.mark.configure
211+
def test_pep517_wheel_time_hash(tmp_path, monkeypatch):
212+
dist = tmp_path / "dist"
213+
dist.mkdir()
214+
monkeypatch.chdir(HELLO_PEP518)
215+
monkeypatch.setenv("SOURCE_DATE_EPOCH", "12345")
216+
if Path("dist").is_dir():
217+
shutil.rmtree("dist")
218+
out = build_wheel(str(dist))
219+
wheel = dist / out
220+
hash1 = hashlib.sha256(wheel.read_bytes()).hexdigest()
221+
222+
time.sleep(2)
223+
Path("src/main.cpp").touch()
224+
225+
if Path("dist").is_dir():
226+
shutil.rmtree("dist")
227+
228+
out = build_wheel(str(dist))
229+
wheel = dist / out
230+
231+
hash2 = hashlib.sha256(wheel.read_bytes()).hexdigest()
232+
233+
assert hash1 == hash2

tests/test_pyproject_pep518.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
DIR = Path(__file__).parent.resolve()
1313
HELLO_PEP518 = DIR / "packages/simple_pyproject_ext"
14-
KNOWN_SDIST_HASH = "03455cc6996c1d0d4977bedb611180cf561ade9d70d7b5d1216a40405adf7b47"
1514

1615

1716
@pytest.mark.integration
@@ -35,8 +34,18 @@ def test_pep518_sdist(pep518, virtualenv):
3534
(sdist,) = dist.iterdir()
3635
assert "cmake-example-0.0.1.tar.gz" == sdist.name
3736

38-
if sys.version_info >= (3, 9) and not sys.platform.startswith("win32"):
39-
assert hashlib.sha256(sdist.read_bytes()).hexdigest() == KNOWN_SDIST_HASH
37+
if not sys.platform.startswith("win32"):
38+
hash = hashlib.sha256(sdist.read_bytes()).hexdigest()
39+
if sys.version_info < (3, 9):
40+
assert (
41+
hash
42+
== "09b0593a80d0b0c086fddb99378e6dc75ba50e041076cd4a9a7afe4053407362"
43+
)
44+
else:
45+
assert (
46+
hash
47+
== "03455cc6996c1d0d4977bedb611180cf561ade9d70d7b5d1216a40405adf7b47"
48+
)
4049

4150
with tarfile.open(sdist) as f:
4251
file_names = set(f.getnames())

0 commit comments

Comments
 (0)