Skip to content

Commit

Permalink
Merge branch 'main' into tox
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Jan 13, 2023
2 parents afee23d + 237fba4 commit ebce80c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/unit/elf/test_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import shutil
from pathlib import Path
from unittest.mock import ANY, call
Expand All @@ -23,6 +22,8 @@
from snapcraft import elf
from snapcraft.elf import errors

PATCHELF_PATH = "/path/to/patchelf"


@pytest.mark.usefixtures("fake_tools")
def test_patcher(fake_elf):
Expand Down Expand Up @@ -79,20 +80,21 @@ def patcher():
yield elf.Patcher(
dynamic_linker="/my/dynamic/linker",
root_path=Path("/snap/foo/current"),
preferred_patchelf=PATCHELF_PATH,
)


def test_patcher_patch_rpath(mocker, patcher, elf_file):
run_mock = mocker.patch("subprocess.check_call")

mocker.patch("subprocess.check_output", return_value=b"\n")
expected_proposed_rpath = list(elf_file.dependencies)[0].path.parent
assert patcher.get_current_rpath(elf_file) == []

patcher.patch(elf_file=elf_file)
assert run_mock.mock_calls == [
call(
[
"/usr/bin/patchelf",
PATCHELF_PATH,
"--set-interpreter",
"/my/dynamic/linker",
"--force-rpath",
Expand All @@ -118,7 +120,7 @@ def test_patcher_patch_existing_rpath_origin(mocker, patcher, elf_file):
assert run_mock.mock_calls == [
call(
[
"/usr/bin/patchelf",
PATCHELF_PATH,
"--set-interpreter",
"/my/dynamic/linker",
"--force-rpath",
Expand All @@ -144,7 +146,7 @@ def test_patcher_patch_existing_rpath_not_origin(mocker, patcher, elf_file):
assert run_mock.mock_calls == [
call(
[
"/usr/bin/patchelf",
PATCHELF_PATH,
"--set-interpreter",
"/my/dynamic/linker",
"--force-rpath",
Expand All @@ -158,6 +160,7 @@ def test_patcher_patch_existing_rpath_not_origin(mocker, patcher, elf_file):

def test_patcher_patch_rpath_same_interpreter(mocker, patcher, elf_file):
run_mock = mocker.patch("subprocess.check_call")
mocker.patch("subprocess.check_output", return_value=b"\n")
patcher._dynamic_linker = elf_file.interp

expected_proposed_rpath = list(elf_file.dependencies)[0].path.parent
Expand All @@ -167,7 +170,7 @@ def test_patcher_patch_rpath_same_interpreter(mocker, patcher, elf_file):
assert run_mock.mock_calls == [
call(
[
"/usr/bin/patchelf",
PATCHELF_PATH,
"--force-rpath",
"--set-rpath",
str(expected_proposed_rpath),
Expand All @@ -190,7 +193,7 @@ def test_patcher_patch_rpath_already_set(mocker, patcher, elf_file):
assert run_mock.mock_calls == [
call(
[
"/usr/bin/patchelf",
PATCHELF_PATH,
"--set-interpreter",
"/my/dynamic/linker",
ANY,
Expand Down

0 comments on commit ebce80c

Please sign in to comment.