From 37f0bbba1399bb68a675d92e72064f82f871cc00 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 28 Aug 2024 07:48:58 +0200 Subject: [PATCH] test sanitize_rpaths toggles --- delocate/cmd/common.py | 2 +- delocate/tests/test_scripts.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/delocate/cmd/common.py b/delocate/cmd/common.py index 7db713e7..9811f559 100644 --- a/delocate/cmd/common.py +++ b/delocate/cmd/common.py @@ -70,6 +70,7 @@ delocate_parser.add_argument( "--sanitize-rpaths", action="store_true", + default=True, help="Remove absolute and relative rpaths from binaries (default)", ) delocate_parser.add_argument( @@ -78,7 +79,6 @@ dest="sanitize_rpaths", help="Don't remove absolute and relative rpaths from binaries", ) -delocate_parser.set_defaults(sanitize_rpaths=True) def verbosity_config(args: Namespace) -> None: diff --git a/delocate/tests/test_scripts.py b/delocate/tests/test_scripts.py index bd3a3ddd..1874a4ff 100644 --- a/delocate/tests/test_scripts.py +++ b/delocate/tests/test_scripts.py @@ -21,6 +21,7 @@ import pytest from pytest_console_scripts import ScriptRunner +from ..cmd.common import delocate_parser from ..tmpdirs import InGivenDirectory, InTemporaryDirectory from ..tools import dir2zip, get_rpaths, set_install_name, zip2dir from ..wheeltools import InWheel @@ -615,10 +616,22 @@ def test_fix_wheel_with_excluded_dylibs( _check_wheel(test2_name, ".dylibs") +def test_sanitize_rpaths_flag() -> None: + args = delocate_parser.parse_args([]) + assert args.sanitize_rpaths + args = delocate_parser.parse_args(["--sanitize-rpaths"]) + assert args.sanitize_rpaths + args = delocate_parser.parse_args(["--no-sanitize-rpaths"]) + assert not args.sanitize_rpaths + + @pytest.mark.xfail( # type: ignore[misc] sys.platform != "darwin", reason="Needs macOS linkage." ) -def test_sanitize_command(tmp_path: Path, script_runner: ScriptRunner) -> None: +@pytest.mark.parametrize("sanitize_rpaths", [True, False]) +def test_sanitize_command( + tmp_path: Path, script_runner: ScriptRunner, sanitize_rpaths: bool +) -> None: unpack_dir = tmp_path / "unpack" zip2dir(RPATH_WHEEL, unpack_dir) assert "libs/" in set( @@ -630,18 +643,26 @@ def test_sanitize_command(tmp_path: Path, script_runner: ScriptRunner) -> None: libs_path.mkdir() shutil.copy(DATA_PATH / "libextfunc_rpath.dylib", libs_path) shutil.copy(DATA_PATH / "libextfunc2_rpath.dylib", libs_path) + cmd = ["delocate-wheel", "-vv"] + if not sanitize_rpaths: + cmd.append("--no-sanitize-rpaths") result = script_runner.run( - ["delocate-wheel", "-vv", "--sanitize-rpaths", rpath_wheel], + cmd + [rpath_wheel], check=True, cwd=tmp_path, ) - assert "Sanitize: Deleting rpath 'libs/' from" in result.stderr + if sanitize_rpaths: + assert "Sanitize: Deleting rpath 'libs/' from" in result.stderr + else: + assert "Deleting rpath" not in result.stderr unpack_dir = tmp_path / "unpack" zip2dir(rpath_wheel, unpack_dir) - assert "libs/" not in set( - get_rpaths(str(unpack_dir / "fakepkg/subpkg/module2.abi3.so")) - ) + rpaths = set(get_rpaths(str(unpack_dir / "fakepkg/subpkg/module2.abi3.so"))) + if sanitize_rpaths: + assert "libs/" not in rpaths + else: + assert "libs/" in rpaths @pytest.mark.xfail( # type: ignore[misc]