|
| 1 | +import os |
| 2 | +import platform |
| 3 | +import sys |
| 4 | +import sysconfig |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +# To run these tests, the following three environment variables must be set, |
| 10 | +# reflecting the cross-platform environment that is in effect.' |
| 11 | +PYTHON_CROSS_PLATFORM = os.getenv("PYTHON_CROSS_PLATFORM", "unknown") |
| 12 | +PYTHON_CROSS_SLICE = os.getenv("PYTHON_CROSS_SLICE", "unknown") |
| 13 | +PYTHON_CROSS_MULTIARCH = os.getenv("PYTHON_CROSS_MULTIARCH", "unknown") |
| 14 | + |
| 15 | +# Determine some file system anchor points. |
| 16 | +VENV_PREFIX = Path(__file__).parent.parent / "cross-venv" |
| 17 | +SUPPORT_PREFIX = ( |
| 18 | + Path(__file__).parent.parent |
| 19 | + / "support" |
| 20 | + / f"{sys.version_info.major}.{sys.version_info.minor}" |
| 21 | + / PYTHON_CROSS_PLATFORM |
| 22 | + / "Python.xcframework" |
| 23 | + / PYTHON_CROSS_SLICE |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +########################################################################### |
| 28 | +# sys |
| 29 | +########################################################################### |
| 30 | + |
| 31 | +def test_sys_platform(): |
| 32 | + assert sys.platform == PYTHON_CROSS_PLATFORM.lower() |
| 33 | + |
| 34 | + |
| 35 | +def test_sys_cross_compiling(): |
| 36 | + assert sys.cross_compiling |
| 37 | + |
| 38 | + |
| 39 | +def test_sys_multiarch(): |
| 40 | + assert sys.implementation._multiarch == PYTHON_CROSS_MULTIARCH |
| 41 | + |
| 42 | + |
| 43 | +def test_sys_base_prefix(): |
| 44 | + assert Path(sys.base_prefix) == SUPPORT_PREFIX |
| 45 | + |
| 46 | + |
| 47 | +def test_sys_base_exec_prefix(): |
| 48 | + assert Path(sys.base_exec_prefix) == SUPPORT_PREFIX |
| 49 | + |
| 50 | + |
| 51 | +########################################################################### |
| 52 | +# platform |
| 53 | +########################################################################### |
| 54 | + |
| 55 | +def test_platform_system(): |
| 56 | + assert platform.system() == PYTHON_CROSS_PLATFORM |
| 57 | + |
| 58 | + |
| 59 | +########################################################################### |
| 60 | +# sysconfig |
| 61 | +########################################################################### |
| 62 | + |
| 63 | +def test_sysconfig_get_platform(): |
| 64 | + parts = sysconfig.get_platform().split("-", 2) |
| 65 | + assert parts[0] == PYTHON_CROSS_PLATFORM.lower() |
| 66 | + assert parts[2] == PYTHON_CROSS_MULTIARCH |
| 67 | + |
| 68 | + |
| 69 | +def test_sysconfig_get_sysconfigdata_name(): |
| 70 | + parts = sysconfig._get_sysconfigdata_name().split("_", 4) |
| 71 | + assert parts[3] == PYTHON_CROSS_PLATFORM.lower() |
| 72 | + assert parts[4] == PYTHON_CROSS_MULTIARCH |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.parametrize( |
| 76 | + "name, prefix", |
| 77 | + [ |
| 78 | + # Paths that should be relative to the support folder |
| 79 | + ("stdlib", SUPPORT_PREFIX), |
| 80 | + ("include", SUPPORT_PREFIX), |
| 81 | + ("platinclude", SUPPORT_PREFIX), |
| 82 | + ("stdlib", SUPPORT_PREFIX), |
| 83 | + # paths that should be relative to the venv |
| 84 | + ("platstdlib", VENV_PREFIX), |
| 85 | + ("purelib", VENV_PREFIX), |
| 86 | + ("platlib", VENV_PREFIX), |
| 87 | + ("scripts", VENV_PREFIX), |
| 88 | + ("data", VENV_PREFIX), |
| 89 | + ] |
| 90 | +) |
| 91 | +def test_sysconfig_get_paths(name, prefix): |
| 92 | + assert sysconfig.get_paths()[name].startswith(str(prefix)) |
0 commit comments