| 1 |
import platform |
| 2 |
import struct |
| 3 |
import sys |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from auditwheel.architecture import Architecture |
| 8 |
|
| 9 |
|
| 10 |
@pytest.mark.parametrize( |
| 11 |
("sys_platform", "reported_arch", "expected_arch"), |
| 12 |
[ |
| 13 |
("linux", "armv7l", Architecture.armv7l), |
| 14 |
("linux", "armv8l", Architecture.armv7l), |
| 15 |
("linux", "aarch64", Architecture.armv7l), |
| 16 |
("linux", "i686", Architecture.i686), |
| 17 |
("linux", "x86_64", Architecture.i686), |
| 18 |
("win32", "x86", Architecture.i686), |
| 19 |
("win32", "AMD64", Architecture.i686), |
| 20 |
], |
| 21 |
) |
| 22 |
def test_32bits_arch_name(sys_platform, reported_arch, expected_arch, monkeypatch): |
| 23 |
monkeypatch.setattr(sys, "platform", sys_platform) |
| 24 |
monkeypatch.setattr(platform, "machine", lambda: reported_arch) |
| 25 |
machine = Architecture.detect(bits=32) |
| 26 |
assert machine == expected_arch |
| 27 |
|
| 28 |
|
| 29 |
@pytest.mark.parametrize( |
| 30 |
("sys_platform", "reported_arch", "expected_arch"), |
| 31 |
[ |
| 32 |
("linux", "armv8l", Architecture.aarch64), |
| 33 |
("linux", "aarch64", Architecture.aarch64), |
| 34 |
("linux", "ppc64le", Architecture.ppc64le), |
| 35 |
("linux", "i686", Architecture.x86_64), |
| 36 |
("linux", "x86_64", Architecture.x86_64), |
| 37 |
("darwin", "arm64", Architecture.aarch64), |
| 38 |
("darwin", "x86_64", Architecture.x86_64), |
| 39 |
("win32", "ARM64", Architecture.aarch64), |
| 40 |
("win32", "AMD64", Architecture.x86_64), |
| 41 |
], |
| 42 |
) |
| 43 |
def test_64bits_arch_name(sys_platform, reported_arch, expected_arch, monkeypatch): |
| 44 |
monkeypatch.setattr(sys, "platform", sys_platform) |
| 45 |
monkeypatch.setattr(platform, "machine", lambda: reported_arch) |
| 46 |
machine = Architecture.detect(bits=64) |
| 47 |
assert machine == expected_arch |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.parametrize( |
| 51 |
("maxsize", "sizeof_voidp", "expected"), |
| 52 |
[ |
| 53 |
# 64-bit |
| 54 |
(9223372036854775807, 8, Architecture.x86_64), |
| 55 |
# 32-bit |
| 56 |
(2147483647, 4, Architecture.i686), |
| 57 |
# 64-bit w/ 32-bit sys.maxsize: GraalPy, IronPython, Jython |
| 58 |
(2147483647, 8, Architecture.x86_64), |
| 59 |
], |
| 60 |
) |
| 61 |
def test_arch_name_bits(maxsize, sizeof_voidp, expected, monkeypatch): |
| 62 |
def _calcsize(fmt): |
| 63 |
assert fmt == "P" |
| 64 |
return sizeof_voidp |
| 65 |
|
| 66 |
monkeypatch.setattr(platform, "machine", lambda: "x86_64") |
| 67 |
monkeypatch.setattr(sys, "maxsize", maxsize) |
| 68 |
monkeypatch.setattr(struct, "calcsize", _calcsize) |
| 69 |
machine = Architecture.detect() |
| 70 |
assert machine == expected |
| 71 |
|
| 72 |
|
| 73 |
@pytest.mark.parametrize( |
| 74 |
("smaller", "larger"), |
| 75 |
[ |
| 76 |
(Architecture.x86_64, Architecture.x86_64_v4), |
| 77 |
(Architecture.x86_64, Architecture.x86_64), |
| 78 |
(Architecture.x86_64, Architecture.x86_64_v2), |
| 79 |
(Architecture.x86_64_v2, Architecture.x86_64_v3), |
| 80 |
(Architecture.x86_64_v3, Architecture.x86_64_v4), |
| 81 |
], |
| 82 |
) |
| 83 |
def test_order_valid(smaller, larger): |
| 84 |
assert smaller.is_subset(larger) |
| 85 |
assert larger.is_superset(smaller) |
| 86 |
|
| 87 |
|
| 88 |
@pytest.mark.parametrize( |
| 89 |
("smaller", "larger"), |
| 90 |
[ |
| 91 |
(Architecture.x86_64, Architecture.x86_64_v4), |
| 92 |
(Architecture.x86_64, Architecture.x86_64_v2), |
| 93 |
(Architecture.x86_64_v2, Architecture.x86_64_v3), |
| 94 |
(Architecture.x86_64_v3, Architecture.x86_64_v4), |
| 95 |
(Architecture.aarch64, Architecture.x86_64), |
| 96 |
(Architecture.x86_64, Architecture.aarch64), |
| 97 |
], |
| 98 |
) |
| 99 |
def test_order_invalid(smaller, larger): |
| 100 |
assert not smaller.is_superset(larger) |
| 101 |
assert not larger.is_subset(smaller) |