Debian Codegraph @

tests/unit/test_lddtree.py

raw
1 import os
2 from pathlib import Path
3
4 import pytest
5
6 from auditwheel.architecture import Architecture
7 from auditwheel.lddtree import LIBPYTHON_RE, ld_paths_from_arg, ldd, parse_ld_paths
8 from auditwheel.libc import Libc
9 from auditwheel.tools import zip2dir
10
11 HERE = Path(__file__).parent.resolve(strict=True)
12
13
14 @pytest.mark.parametrize(
15 "soname",
16 [
17 "libpython3.7m.so.1.0",
18 "libpython3.9.so.1.0",
19 "libpython3.10.so.1.0",
20 "libpython999.999.so.1.0",
21 ],
22 )
23 def test_libpython_re_match(soname: str) -> None:
24 assert LIBPYTHON_RE.match(soname)
25
26
27 @pytest.mark.parametrize(
28 "soname",
29 [
30 "libpython3.7m.soa1.0",
31 "libpython3.9.so.1a0",
32 ],
33 )
34 def test_libpython_re_nomatch(soname: str) -> None:
35 assert LIBPYTHON_RE.match(soname) is None
36
37
38 def test_libpython(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
39 wheel = (
40 HERE / ".." / "integration" / "python_mscl-67.0.1.0-cp313-cp313-manylinux2014_aarch64.whl"
41 )
42 so = tmp_path / "python_mscl" / "_mscl.so"
43 zip2dir(wheel, tmp_path)
44 result = ldd(so)
45 assert "Skip libpython3.13.so.1.0 resolution" in caplog.text
46 assert result.interpreter is None
47 assert result.libc == Libc.GLIBC
48 assert result.platform.baseline_architecture == Architecture.aarch64
49 assert result.platform.extended_architecture is None
50 assert result.path is not None
51 assert result.realpath.samefile(so)
52 assert result.needed == (
53 "libpython3.13.so.1.0",
54 "libstdc++.so.6",
55 "libm.so.6",
56 "libgcc_s.so.1",
57 "libc.so.6",
58 "ld-linux-aarch64.so.1",
59 )
60 # libpython must be present in dependencies without path
61 libpython = result.libraries["libpython3.13.so.1.0"]
62 assert libpython.soname == "libpython3.13.so.1.0"
63 assert libpython.path is None
64 assert libpython.platform is None
65 assert libpython.realpath is None
66 assert libpython.needed == ()
67
68
69 def test_parse_ld_paths():
70 here = str(HERE)
71 parent = str(HERE.parent)
72
73 assert parse_ld_paths("") == []
74 assert parse_ld_paths(f"{here}") == [here]
75 assert parse_ld_paths(f"{parent}") == [parent]
76
77 # Order is preserved.
78 assert parse_ld_paths(f"{here}:{parent}") == [here, parent]
79 assert parse_ld_paths(f"{parent}:{here}") == [parent, here]
80
81 # `..` references are normalized.
82 assert parse_ld_paths(f"{here}/..") == [parent]
83
84 # Duplicate paths are deduplicated.
85 assert parse_ld_paths(f"{here}:{here}") == [here]
86
87 # Empty paths are equivalent to $PWD.
88 cwd = str(Path.cwd())
89 assert parse_ld_paths(":") == [cwd]
90 assert parse_ld_paths(f"{here}:") == [here, cwd]
91 assert parse_ld_paths(f":{here}") == [cwd, here]
92
93 # Nonexistent paths are ignored.
94 assert parse_ld_paths("/nonexistent") == []
95 assert parse_ld_paths(f"/nonexistent:{here}") == [here]
96
97
98 @pytest.mark.parametrize("origin", ["$ORIGIN", "${ORIGIN}"])
99 def test_parse_ld_paths_origin(origin):
100 here = str(HERE)
101 parent = str(HERE.parent)
102
103 with pytest.raises(ValueError, match=r"can't expand \$ORIGIN without a path"):
104 parse_ld_paths(origin)
105
106 assert parse_ld_paths(origin, path=__file__) == [here]
107 assert parse_ld_paths(f"{origin}/..", path=__file__) == [parent]
108
109 # Relative paths are made absolute.
110 assert parse_ld_paths(origin, path=os.path.relpath(__file__)) == [here]
111
112
113 @pytest.mark.parametrize(
114 ("arg", "env", "expected"),
115 [
116 (None, "", None),
117 (None, str(HERE.parent), None),
118 ("", "", {"conf": [], "env": [], "interp": []}),
119 (str(HERE), "", {"conf": [str(HERE)], "env": [], "interp": []}),
120 ("", str(HERE), {"conf": [], "env": [str(HERE)], "interp": []}),
121 (
122 str(HERE),
123 str(HERE.parent),
124 {"conf": [str(HERE)], "env": [str(HERE.parent)], "interp": []},
125 ),
126 ],
127 )
128 def test_ld_paths_from_arg(arg, env, expected, monkeypatch):
129 monkeypatch.setitem(os.environ, "AUDITWHEEL_LD_LIBRARY_PATH", env)
130 assert ld_paths_from_arg(arg) == expected