| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import shutil |
| 4 |
import subprocess |
| 5 |
from pathlib import Path |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
from auditwheel.architecture import Architecture |
| 10 |
|
| 11 |
HERE = Path(__file__).parent.resolve() |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.parametrize("mode", ["repair", "show"]) |
| 15 |
def test_non_platform_wheel_pure(mode): |
| 16 |
wheel = HERE / "plumbum-1.6.8-py2.py3-none-any.whl" |
| 17 |
proc = subprocess.run( |
| 18 |
["auditwheel", mode, str(wheel)], |
| 19 |
stderr=subprocess.PIPE, |
| 20 |
text=True, |
| 21 |
check=False, |
| 22 |
) |
| 23 |
assert proc.returncode == 1 |
| 24 |
assert "This does not look like a platform wheel" in proc.stderr |
| 25 |
assert "AttributeError" not in proc.stderr |
| 26 |
|
| 27 |
|
| 28 |
@pytest.mark.parametrize( |
| 29 |
("mode", "samefile"), |
| 30 |
[("repair", False), ("repair", True), ("show", False)], |
| 31 |
) |
| 32 |
def test_non_platform_wheel_pure_allow(mode: str, samefile: bool, tmp_path: Path) -> None: |
| 33 |
wheel = HERE / "plumbum-1.6.8-py2.py3-none-any.whl" |
| 34 |
dest_wheel = tmp_path / wheel.name |
| 35 |
if samefile: |
| 36 |
shutil.copy2(wheel, dest_wheel) |
| 37 |
wheel = dest_wheel |
| 38 |
args = ["auditwheel", mode, "--allow-pure-python-wheel", str(wheel)] |
| 39 |
if mode == "repair": |
| 40 |
args.extend(["-w", str(tmp_path)]) |
| 41 |
proc = subprocess.run( |
| 42 |
args, |
| 43 |
stderr=subprocess.PIPE, |
| 44 |
text=True, |
| 45 |
check=True, |
| 46 |
) |
| 47 |
assert "This does not look like a platform wheel" in proc.stderr |
| 48 |
assert "AttributeError" not in proc.stderr |
| 49 |
if mode == "repair": |
| 50 |
assert dest_wheel.is_file() |
| 51 |
assert dest_wheel.read_bytes() == wheel.read_bytes() |
| 52 |
|
| 53 |
|
| 54 |
def test_non_platform_wheel_pure_allow_multiple(tmp_path: Path) -> None: |
| 55 |
wheel = HERE / "plumbum-1.6.8-py2.py3-none-any.whl" |
| 56 |
src_wheels = tmp_path / "src" |
| 57 |
src_wheels.mkdir() |
| 58 |
src_wheel1 = src_wheels / "plumbum-1.6.8-py2-none-any.whl" |
| 59 |
src_wheel2 = src_wheels / "plumbum-1.6.8-py3-none-any.whl" |
| 60 |
shutil.copy2(wheel, src_wheel1) |
| 61 |
shutil.copy2(wheel, src_wheel2) |
| 62 |
dst_wheels = tmp_path / "dst" |
| 63 |
dst_wheel1 = dst_wheels / src_wheel1.name |
| 64 |
dst_wheel2 = dst_wheels / src_wheel2.name |
| 65 |
|
| 66 |
args = [ |
| 67 |
"auditwheel", |
| 68 |
"repair", |
| 69 |
"-w", |
| 70 |
str(dst_wheels), |
| 71 |
"--allow-pure-python-wheel", |
| 72 |
str(src_wheel1), |
| 73 |
str(src_wheel2), |
| 74 |
] |
| 75 |
proc = subprocess.run( |
| 76 |
args, |
| 77 |
stderr=subprocess.PIPE, |
| 78 |
text=True, |
| 79 |
check=True, |
| 80 |
) |
| 81 |
assert "This does not look like a platform wheel" in proc.stderr |
| 82 |
assert "AttributeError" not in proc.stderr |
| 83 |
for dst_wheel in [dst_wheel1, dst_wheel2]: |
| 84 |
assert dst_wheel.is_file() |
| 85 |
assert dst_wheel.read_bytes() == wheel.read_bytes() |
| 86 |
|
| 87 |
|
| 88 |
@pytest.mark.parametrize("mode", ["repair", "show"]) |
| 89 |
@pytest.mark.parametrize("arch", ["armv5l", "mips64"]) |
| 90 |
@pytest.mark.parametrize("allow_pure_python", [True, False]) |
| 91 |
def test_non_platform_wheel_unknown_arch(mode, arch, allow_pure_python, tmp_path): |
| 92 |
wheel_name = f"testsimple-0.0.1-cp313-cp313-linux_{arch}.whl" |
| 93 |
wheel_path = HERE / "arch-wheels" / "glibc" / wheel_name |
| 94 |
wheel_x86_64 = tmp_path / f"{wheel_path.stem}_x86_64.whl" |
| 95 |
wheel_x86_64.symlink_to(wheel_path) |
| 96 |
args = ["auditwheel", mode, str(wheel_x86_64)] |
| 97 |
if allow_pure_python: |
| 98 |
args.append("--allow-pure-python-wheel") |
| 99 |
proc = subprocess.run( |
| 100 |
args, |
| 101 |
stderr=subprocess.PIPE, |
| 102 |
text=True, |
| 103 |
check=False, |
| 104 |
) |
| 105 |
assert proc.returncode == 1 |
| 106 |
assert "Invalid binary wheel: no ELF executable or" in proc.stderr |
| 107 |
assert "unknown architecture" in proc.stderr |
| 108 |
assert "AttributeError" not in proc.stderr |
| 109 |
|
| 110 |
|
| 111 |
@pytest.mark.parametrize("mode", ["repair", "show"]) |
| 112 |
@pytest.mark.parametrize( |
| 113 |
"arch", |
| 114 |
["aarch64", "armv7l", "i686", "x86_64", "ppc64le", "s390x"], |
| 115 |
) |
| 116 |
@pytest.mark.parametrize("allow_pure_python", [True, False]) |
| 117 |
def test_non_platform_wheel_bad_arch(mode, arch, allow_pure_python, tmp_path): |
| 118 |
host_arch = Architecture.detect().value |
| 119 |
if host_arch == arch: |
| 120 |
pytest.skip("host architecture") |
| 121 |
wheel_name = f"testsimple-0.0.1-cp313-cp313-linux_{arch}.whl" |
| 122 |
wheel_path = HERE / "arch-wheels" / "glibc" / wheel_name |
| 123 |
wheel_host = tmp_path / f"{wheel_path.stem}_{host_arch}.whl" |
| 124 |
wheel_host.symlink_to(wheel_path) |
| 125 |
args = ["auditwheel", mode, str(wheel_host)] |
| 126 |
if allow_pure_python: |
| 127 |
args.append("--allow-pure-python-wheel") |
| 128 |
proc = subprocess.run( |
| 129 |
args, |
| 130 |
stderr=subprocess.PIPE, |
| 131 |
text=True, |
| 132 |
check=False, |
| 133 |
) |
| 134 |
assert proc.returncode == 1 |
| 135 |
assert "Invalid binary wheel: no ELF executable or" in proc.stderr |
| 136 |
assert f"{arch} architecture" in proc.stderr |
| 137 |
assert "AttributeError" not in proc.stderr |