File: test_wheel_abi.py

package info (click to toggle)
python-auditwheel 5.3.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: python: 4,270; ansic: 205; cpp: 58; makefile: 20; f90: 12
file content (49 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download
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
import os

import pretend
import pytest

from auditwheel import wheel_abi


class TestGetWheelElfdata:
    @pytest.mark.parametrize(
        "filenames, message",
        [
            (
                # A single invalid file
                [os.sep.join(["purelib", "foo"])],
                "Invalid binary wheel, found the following shared library/libraries in"
                " purelib folder:\n\tfoo\nThe wheel has to be platlib compliant in "
                "order to be repaired by auditwheel.",
            ),
            (
                # Multiple invalid files
                [os.sep.join(["purelib", "foo"]), os.sep.join(["purelib", "bar"])],
                "Invalid binary wheel, found the following shared library/libraries in"
                " purelib folder:\n\tfoo\n\tbar\nThe wheel has to be platlib compliant"
                " in order to be repaired by auditwheel.",
            ),
        ],
    )
    def test_finds_shared_library_in_purelib(self, filenames, message, monkeypatch):
        entered_context = pretend.stub(iter_files=lambda: filenames)
        context = pretend.stub(
            __enter__=lambda: entered_context, __exit__=lambda *a: None
        )
        InGenericPkgCtx = pretend.stub(__call__=lambda a: context)

        monkeypatch.setattr(wheel_abi, "InGenericPkgCtx", InGenericPkgCtx)
        monkeypatch.setattr(
            wheel_abi, "elf_is_python_extension", lambda fn, elf: (fn, elf)
        )
        monkeypatch.setattr(
            wheel_abi,
            "elf_file_filter",
            lambda fns: [(fn, pretend.stub()) for fn in fns],
        )

        with pytest.raises(RuntimeError) as exec_info:
            wheel_abi.get_wheel_elfdata("/fakepath")

        assert exec_info.value.args == (message,)