diff --git a/delocate/tests/test_delocating.py b/delocate/tests/test_delocating.py index 8f46dc57..b5139527 100644 --- a/delocate/tests/test_delocating.py +++ b/delocate/tests/test_delocating.py @@ -12,9 +12,12 @@ from typing import Any, Callable, Dict, Iterable, List, Set, Text, Tuple import pytest +from packaging.utils import InvalidWheelFilename +from packaging.version import Version from ..delocating import ( DelocationError, + _get_archs_and_version_from_wheel_name, bads_report, check_archs, copy_recurse, @@ -705,3 +708,24 @@ def test_dyld_fallback_library_path_loses_to_basename() -> None: # tmpdir can end up in /var, and that can be symlinked to # /private/var, so we'll use realpath to resolve the two assert_equal(predicted_lib_location, os.path.realpath(libb)) + + +def test_get_archs_and_version_from_wheel_name() -> None: + # Test getting archs and version from wheel name + assert _get_archs_and_version_from_wheel_name( + "foo-1.0-py310-abi3-macosx_10_9_universal2.whl" + ) == { + "universal2": Version("10.9"), + } + assert _get_archs_and_version_from_wheel_name( + "foo-1.0-py310-abi3-macosx_12_0_arm64.whl" + ) == { + "arm64": Version("12.0"), + } + with pytest.raises(InvalidWheelFilename, match="Invalid wheel filename"): + _get_archs_and_version_from_wheel_name("foo.whl") + + with pytest.raises(ValueError, match="Invalid platform tag"): + _get_archs_and_version_from_wheel_name( + "foo-1.0-py310-abi3-manylinux1.whl" + ) diff --git a/delocate/tests/test_scripts.py b/delocate/tests/test_scripts.py index fedaeeb2..fba38f54 100644 --- a/delocate/tests/test_scripts.py +++ b/delocate/tests/test_scripts.py @@ -738,3 +738,35 @@ def test_delocate_wheel_verify_name_universal2_verify_crash( assert result.returncode != 0 assert "Library dependencies do not satisfy target MacOS" in result.stderr assert "libam1.dylib has a minimum target of 12.0" in result.stderr + + +@pytest.mark.xfail( # type: ignore[misc] + sys.platform != "darwin", reason="Needs macOS linkage." +) +@pytest.mark.script_launch_mode("subprocess") +def test_delocate_wheel_verify_name_universal2_verify_crash_env_var( + plat_wheel: PlatWheel, + script_runner: ScriptRunner, + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + zip2dir(plat_wheel.whl, tmp_path / "plat") + shutil.copy( + DATA_PATH / "libam1_12.dylib", + tmp_path / "plat" / "fakepkg1" / "libam1.dylib", + ) + whl_10_9 = tmp_path / "plat2-1.0-cp311-cp311-macosx_10_9_universal2.whl" + dir2zip(tmp_path / "plat", whl_10_9) + result = script_runner.run( + [ + "delocate-wheel", + whl_10_9, + ], + check=False, + cwd=tmp_path, + env={"MACOSX_DEPLOYMENT_TARGET": "10.9"}, + shell=True, + ) + assert result.returncode != 0 + assert "Library dependencies do not satisfy target MacOS" in result.stderr + assert "libam1.dylib has a minimum target of 12.0" in result.stderr