Skip to content

Commit 79ca351

Browse files
committed
add tests for main_repair
1 parent f437450 commit 79ca351

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/auditwheel/main_repair.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ def execute(args: argparse.Namespace, parser: argparse.ArgumentParser) -> int:
158158
if libc is None:
159159
libc = Libc.GLIBC
160160
if libc != Libc.GLIBC:
161-
msg = f"can't repair wheel {wheel_filename} with {libc} libc to a wheel targeting GLIBC"
161+
msg = f"can't repair wheel {wheel_filename} with {libc.name} libc to a wheel targeting GLIBC"
162162
parser.error(msg)
163163
elif plat_base.startswith("musllinux"):
164164
if libc is None:
165165
libc = Libc.MUSL
166166
if libc != Libc.MUSL:
167-
msg = f"can't repair wheel {wheel_filename} with {libc} libc to a wheel targeting MUSL"
167+
msg = f"can't repair wheel {wheel_filename} with {libc.name} libc to a wheel targeting MUSL"
168168
parser.error(msg)
169169

170170
logger.info("Repairing %s", wheel_filename)

tests/unit/test_main.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77

8+
from auditwheel.libc import Libc, LibcVersion
89
from auditwheel.main import main
910

1011
on_supported_platform = pytest.mark.skipif(
@@ -37,14 +38,58 @@ def test_help(monkeypatch, capsys):
3738
assert "usage: auditwheel [-h] [-V] [-v] command ..." in captured.out
3839

3940

40-
def test_show_unexisting_wheel(monkeypatch, capsys, tmp_path):
41+
@pytest.mark.parametrize("function", ["show", "repair"])
42+
def test_unexisting_wheel(monkeypatch, capsys, tmp_path, function):
4143
monkeypatch.setattr(sys, "platform", "linux")
4244
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
4345
wheel = str(tmp_path / "not-a-file.whl")
44-
monkeypatch.setattr(sys, "argv", ["dummy", "show", wheel])
46+
monkeypatch.setattr(sys, "argv", ["auditwheel", function, wheel])
4547

4648
with pytest.raises(SystemExit):
4749
main()
4850

4951
captured = capsys.readouterr()
5052
assert "No such file" in captured.err
53+
54+
55+
@pytest.mark.parametrize(
56+
("libc", "filename", "plat", "message"),
57+
[
58+
(
59+
Libc.GLIBC,
60+
"foo-1.0-py3-none-manylinux1_aarch64.whl",
61+
"manylinux_2_28_x86_64",
62+
"can't repair wheel foo-1.0-py3-none-manylinux1_aarch64.whl with aarch64 architecture to a wheel targeting x86_64",
63+
),
64+
(
65+
Libc.GLIBC,
66+
"foo-1.0-py3-none-musllinux_1_1_x86_64.whl",
67+
"manylinux_2_28_x86_64",
68+
"can't repair wheel foo-1.0-py3-none-musllinux_1_1_x86_64.whl with MUSL libc to a wheel targeting GLIBC",
69+
),
70+
(
71+
Libc.MUSL,
72+
"foo-1.0-py3-none-manylinux1_x86_64.whl",
73+
"musllinux_1_1_x86_64",
74+
"can't repair wheel foo-1.0-py3-none-manylinux1_x86_64.whl with GLIBC libc to a wheel targeting MUSL",
75+
),
76+
],
77+
)
78+
def test_repair_wheel_mismatch(
79+
monkeypatch, capsys, tmp_path, libc, filename, plat, message
80+
):
81+
monkeypatch.setattr(sys, "platform", "linux")
82+
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
83+
monkeypatch.setattr(Libc, "detect", lambda: libc)
84+
monkeypatch.setattr(Libc, "get_current_version", lambda _: LibcVersion(1, 1))
85+
wheel = tmp_path / filename
86+
wheel.write_text("")
87+
monkeypatch.setattr(
88+
sys, "argv", ["auditwheel", "repair", "--plat", plat, str(wheel)]
89+
)
90+
91+
with pytest.raises(SystemExit):
92+
main()
93+
94+
captured = capsys.readouterr()
95+
assert message in captured.err

0 commit comments

Comments
 (0)