-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_check.py
53 lines (40 loc) · 1.37 KB
/
test_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import hashlib
import os
import platform
from collections import defaultdict
from pathlib import Path
import pytest
from ..util import check_wheel_installs_and_runs, is_wheel_compatible
BUF_SIZE = 65536
GEN_PATH = os.environ.get("TESTWHEEL_GENERATE_PATH")
if GEN_PATH is None:
pytest.skip(allow_module_level=True)
def hash(file: Path) -> str:
md5 = hashlib.md5()
with open(file, "rb") as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
return md5.hexdigest()
@pytest.mark.parametrize(
"patched_wheel",
Path(GEN_PATH).glob("**/*.whl"),
ids=lambda p: os.path.relpath(str(p), GEN_PATH),
)
def test_check_patched_wheel(patched_wheel: Path) -> None:
if not is_wheel_compatible(patched_wheel):
pytest.skip(f"Wheel not installable on {platform.platform()}: {patched_wheel.name}")
check_wheel_installs_and_runs(patched_wheel)
def test_check_reproducibility() -> None:
hashes = defaultdict(set)
wheels = Path(GEN_PATH).glob("**/*.whl")
for wheel in wheels:
hashes[wheel.name].add(hash(wheel))
non_reproducible = []
for wheel_name, hash_set in hashes.items():
if len(hash_set) > 1:
non_reproducible.append(wheel_name)
if non_reproducible:
raise AssertionError(f"Wheels are not reproducible: {non_reproducible}")