Skip to content

Commit

Permalink
Make platform wheel tests location independent.
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Jul 22, 2021
1 parent d895252 commit da602a0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 33 deletions.
25 changes: 25 additions & 0 deletions delocate/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pathlib import Path
from typing import Iterator

import pytest

from delocate.tools import set_install_name
from delocate.wheeltools import InWheelCtx
from .test_wheelies import PlatWheel, STRAY_LIB_DEP, PLAT_WHEEL


@pytest.fixture
def plat_wheel(tmp_path: Path) -> Iterator[PlatWheel]:
""" Return a modified platform wheel for testing. """
plat_wheel_tmp = str(tmp_path / 'plat-wheel.whl')
stray_lib: str = STRAY_LIB_DEP

with InWheelCtx(PLAT_WHEEL, plat_wheel_tmp):
set_install_name(
'fakepkg1/subpkg/module2.abi3.so',
'libextfunc.dylib',
stray_lib,
)

yield PlatWheel(plat_wheel_tmp, os.path.realpath(stray_lib))
Binary file not shown.
Binary file modified delocate/tests/data/libextfunc.dylib
Binary file not shown.
1 change: 0 additions & 1 deletion delocate/tests/data/wheel_build_path.txt

This file was deleted.

1 change: 1 addition & 0 deletions delocate/tests/pytest_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest


Expand Down
20 changes: 10 additions & 10 deletions delocate/tests/test_libsana.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from .test_install_names import (LIBA, LIBB, LIBC, TEST_LIB, _copy_libs,
EXT_LIBS, LIBSYSTEMB, DATA_PATH)
from .test_wheelies import (PLAT_WHEEL, PURE_WHEEL, STRAY_LIB_DEP)
from .test_wheelies import (PlatWheel, PLAT_WHEEL, PURE_WHEEL)


def get_ext_dict(local_libs):
Expand Down Expand Up @@ -266,19 +266,19 @@ def test_stripped_lib_dict():
) == exp_dict


def test_wheel_libs():
# type: () -> None
def test_wheel_libs(plat_wheel: PlatWheel) -> None:
# Test routine to list dependencies from wheels
assert_equal(wheel_libs(PURE_WHEEL), {})
assert wheel_libs(PURE_WHEEL) == {}
mod2 = pjoin('fakepkg1', 'subpkg', 'module2.abi3.so')
rp_stray = realpath(STRAY_LIB_DEP)
assert wheel_libs(PLAT_WHEEL) == {
rp_stray: {mod2: rp_stray},
realpath(LIBSYSTEMB): {mod2: LIBSYSTEMB, STRAY_LIB_DEP: LIBSYSTEMB},

assert wheel_libs(plat_wheel.whl) == {
plat_wheel.stray_lib: {mod2: plat_wheel.stray_lib},
realpath(LIBSYSTEMB): {
mod2: LIBSYSTEMB, plat_wheel.stray_lib: LIBSYSTEMB
},
}

def filt(fname):
# type: (Text) -> bool
def filt(fname: str) -> bool:
return not fname.endswith(mod2)
assert wheel_libs(PLAT_WHEEL, filt) == {}

Expand Down
37 changes: 22 additions & 15 deletions delocate/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

from .test_install_names import EXT_LIBS
from .test_delocating import _make_libtree, _copy_to, _make_bare_depends
from .test_wheelies import (_fixed_wheel, PLAT_WHEEL, PURE_WHEEL,
STRAY_LIB_DEP, WHEEL_PATCH, WHEEL_PATCH_BAD,
from .test_wheelies import (PlatWheel, _fixed_wheel, PLAT_WHEEL, PURE_WHEEL,
WHEEL_PATCH, WHEEL_PATCH_BAD,
_thin_lib, _thin_mod, _rename_module)
from .test_fuse import assert_same_tree
from .test_wheeltools import (assert_winfo_similar, EXP_ITEMS, EXTRA_PLATS,
Expand Down Expand Up @@ -60,7 +60,7 @@ def _proc_lines(in_str):
DATA_PATH = abspath(pjoin(dirname(__file__), 'data'))


def test_listdeps():
def test_listdeps(plat_wheel: PlatWheel) -> None:
# smokey tests of list dependencies command
local_libs = {
'liba.dylib',
Expand All @@ -80,19 +80,18 @@ def test_listdeps():
assert set(stdout) == set()
assert code == 0
# Multiple paths one with libs
zip2dir(PLAT_WHEEL, 'plat')
zip2dir(plat_wheel.whl, 'plat')
code, stdout, stderr = run_command(
['delocate-listdeps', 'pure', 'plat'])
rp_stray = realpath(STRAY_LIB_DEP)
assert stdout == ['pure:', 'plat:', rp_stray]
assert stdout == ['pure:', 'plat:', plat_wheel.stray_lib]
assert code == 0
# With -d flag, get list of dependending modules
code, stdout, stderr = run_command(
['delocate-listdeps', '-d', 'pure', 'plat'])
assert stdout == [
'pure:',
'plat:',
rp_stray + ':',
plat_wheel.stray_lib + ':',
pjoin('plat', 'fakepkg1', 'subpkg', 'module2.abi3.so'),
]
assert code == 0
Expand All @@ -109,29 +108,37 @@ def test_listdeps():
code, stdout, stderr = run_command(['delocate-listdeps', PURE_WHEEL])
assert set(stdout) == set()
code, stdout, stderr = run_command(
['delocate-listdeps', PURE_WHEEL, PLAT_WHEEL]
['delocate-listdeps', PURE_WHEEL, plat_wheel.whl]
)
assert stdout == [PURE_WHEEL + ':', PLAT_WHEEL + ':', rp_stray]
assert stdout == [
PURE_WHEEL + ':', plat_wheel.whl + ':', plat_wheel.stray_lib
]
# -d flag (is also --dependency flag)
m2 = pjoin('fakepkg1', 'subpkg', 'module2.abi3.so')
code, stdout, stderr = run_command(
['delocate-listdeps', '--depending', PURE_WHEEL, PLAT_WHEEL]
['delocate-listdeps', '--depending', PURE_WHEEL, plat_wheel.whl]
)
assert stdout == [
PURE_WHEEL + ':', PLAT_WHEEL + ':', rp_stray + ':', m2
PURE_WHEEL + ':', plat_wheel.whl + ':', plat_wheel.stray_lib + ':', m2
]
# Can be used with --all
code, stdout, stderr = run_command(
['delocate-listdeps', '--all', '--depending', PURE_WHEEL, PLAT_WHEEL]
[
'delocate-listdeps',
'--all',
'--depending',
PURE_WHEEL,
plat_wheel.whl,
]
)
assert stdout == [
PURE_WHEEL + ':',
PLAT_WHEEL + ':',
rp_stray + ':',
plat_wheel.whl + ':',
plat_wheel.stray_lib + ':',
m2,
EXT_LIBS[1] + ':',
m2,
rp_stray,
plat_wheel.stray_lib,
]


Expand Down
11 changes: 8 additions & 3 deletions delocate/tests/test_wheelies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from glob import glob
import shutil
from subprocess import check_call
from typing import NamedTuple

from ..delocating import (DelocationError, delocate_wheel, patch_wheel,
DLC_PREFIX)
Expand Down Expand Up @@ -39,13 +40,17 @@ def _collect_wheel(globber):
RPATH_WHEEL = _collect_wheel('fakepkg_rpath-1.0-cp*.whl')
STRAY_LIB = pjoin(DATA_PATH, 'libextfunc.dylib')
# The install_name in the wheel for the stray library
with open(pjoin(DATA_PATH, 'wheel_build_path.txt'), 'rt') as fobj:
_wheel_build_path = fobj.read().strip()
STRAY_LIB_DEP = _wheel_build_path + '/fakepkg1/libs/libextfunc.dylib'
STRAY_LIB_DEP = realpath(STRAY_LIB)
WHEEL_PATCH = pjoin(DATA_PATH, 'fakepkg2.patch')
WHEEL_PATCH_BAD = pjoin(DATA_PATH, 'fakepkg2.bad_patch')


class PlatWheel(NamedTuple):
""" Information about a temporary platform wheel. """
whl: str # Path to the wheel.
stray_lib: str # Path to the external library.


def test_fix_pure_python():
# Test fixing a pure python package gives no change
with InTemporaryDirectory():
Expand Down
2 changes: 1 addition & 1 deletion wheel_makers/fakepkg1/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
arch_flags = ['-arch', 'arm64', '-arch', 'x86_64'] # dual arch
check_call(['cc', '-dynamiclib', pjoin(LIBS, 'extfunc.c'),
'-o', EXTLIB] + arch_flags)
check_call(['install_name_tool', '-id', EXTLIB, EXTLIB])
check_call(['install_name_tool', '-id', 'libextfunc.dylib', EXTLIB])

exts = [
Extension(
Expand Down
3 changes: 0 additions & 3 deletions wheel_makers/make_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@ OUT_PATH=../delocate/tests/data
rm $OUT_PATH/fakepkg*.whl
cp */dist/*.whl $OUT_PATH
cp */libs/*.dylib $OUT_PATH
# Record wheel building path
python -c "import os; print(os.path.realpath(os.getcwd()))" \
> $OUT_PATH/wheel_build_path.txt

0 comments on commit da602a0

Please sign in to comment.