|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +def use(x): |
| 7 | + pass |
| 8 | + |
| 9 | + |
| 10 | +def test_dynlib_loading(tmp_path, monkeypatch): |
| 11 | + # fmt: off |
| 12 | + Path(tmp_path / "a.so").write_bytes( |
| 13 | + bytes( |
| 14 | + [ |
| 15 | + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x64, |
| 16 | + 0x79, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x30, 0x01, 0x04, 0x00, 0x00, 0x00, |
| 17 | + 0x00, 0x01, 0x04, 0x01, 0x60, 0x00, 0x00, 0x02, 0x38, 0x03, 0x03, 0x65, |
| 18 | + 0x6e, 0x76, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x00, |
| 19 | + 0x03, 0x65, 0x6e, 0x76, 0x0d, 0x5f, 0x5f, 0x6d, 0x65, 0x6d, 0x6f, 0x72, |
| 20 | + 0x79, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x03, 0x7f, 0x00, 0x03, 0x65, 0x6e, |
| 21 | + 0x76, 0x0c, 0x5f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, |
| 22 | + 0x73, 0x65, 0x03, 0x7f, 0x00, 0x03, 0x02, 0x01, 0x00, 0x07, 0x15, 0x01, |
| 23 | + 0x11, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x6c, |
| 24 | + 0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x00, 0x0a, 0x04, 0x01, 0x02, |
| 25 | + 0x00, 0x0b |
| 26 | + ] |
| 27 | + ) |
| 28 | + ) |
| 29 | + # fmt: on |
| 30 | + monkeypatch.syspath_prepend(tmp_path) |
| 31 | + with pytest.raises( |
| 32 | + ImportError, match="Can only load shared libraries from read only file systems" |
| 33 | + ): |
| 34 | + import a |
| 35 | + |
| 36 | + use(a) |
0 commit comments