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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
from subprocess import CalledProcessError
from unittest.mock import call, patch
import pytest
from auditwheel.patcher import Patchelf
@patch("auditwheel.patcher.find_executable")
def test_patchelf_unavailable(find_executable):
find_executable.return_value = False
with pytest.raises(ValueError):
Patchelf()
@patch("auditwheel.patcher.check_output")
def test_patchelf_check_output_fail(check_output):
check_output.side_effect = CalledProcessError(1, "patchelf --version")
with pytest.raises(ValueError, match="Could not call"):
Patchelf()
@patch("auditwheel.patcher.check_output")
@pytest.mark.parametrize("version", ["0.14", "0.14.1", "0.15"])
def test_patchelf_version_check(check_output, version):
check_output.return_value.decode.return_value = f"patchelf {version}"
Patchelf()
@patch("auditwheel.patcher.check_output")
@pytest.mark.parametrize("version", ["0.13.99", "0.13", "0.9", "0.1"])
def test_patchelf_version_check_fail(check_output, version):
check_output.return_value.decode.return_value = f"patchelf {version}"
with pytest.raises(ValueError, match=f"patchelf {version} found"):
Patchelf()
@patch("auditwheel.patcher._verify_patchelf")
@patch("auditwheel.patcher.check_output")
@patch("auditwheel.patcher.check_call")
class TestPatchElf:
""" "Validate that patchelf is invoked with the correct arguments."""
def test_replace_needed_one(self, check_call, _0, _1):
patcher = Patchelf()
filename = "test.so"
soname_old = "TEST_OLD"
soname_new = "TEST_NEW"
patcher.replace_needed(filename, (soname_old, soname_new))
check_call.assert_called_once_with(
["patchelf", "--replace-needed", soname_old, soname_new, filename]
)
def test_replace_needed_multple(self, check_call, _0, _1):
patcher = Patchelf()
filename = "test.so"
replacements = [
("TEST_OLD1", "TEST_NEW1"),
("TEST_OLD2", "TEST_NEW2"),
]
patcher.replace_needed(filename, *replacements)
check_call.assert_called_once_with(
[
"patchelf",
"--replace-needed",
*replacements[0],
"--replace-needed",
*replacements[1],
filename,
]
)
def test_set_soname(self, check_call, _0, _1):
patcher = Patchelf()
filename = "test.so"
soname_new = "TEST_NEW"
patcher.set_soname(filename, soname_new)
check_call.assert_called_once_with(
["patchelf", "--set-soname", soname_new, filename]
)
def test_set_rpath(self, check_call, _0, _1):
patcher = Patchelf()
patcher.set_rpath("test.so", "$ORIGIN/.lib")
check_call_expected_args = [
call(["patchelf", "--remove-rpath", "test.so"]),
call(
["patchelf", "--force-rpath", "--set-rpath", "$ORIGIN/.lib", "test.so"]
),
]
assert check_call.call_args_list == check_call_expected_args
def test_get_rpath(self, _0, check_output, _1):
patcher = Patchelf()
check_output.return_value = b"existing_rpath"
result = patcher.get_rpath("test.so")
check_output_expected_args = [call(["patchelf", "--print-rpath", "test.so"])]
assert result == check_output.return_value.decode()
assert check_output.call_args_list == check_output_expected_args
|