Skip to content

Commit a03a047

Browse files
committed
Add test suite for cross-envs.
1 parent f93b88a commit a03a047

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

tests/test_cross_env.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 for the tests
16+
# Assumes that the tests are run in a virtual environment named
17+
# `cross-venv`,
18+
VENV_PREFIX = Path(__file__).parent.parent / "cross-venv"
19+
default_support_base = f"support/{sys.version_info.major}.{sys.version_info.minor}/{PYTHON_CROSS_PLATFORM}"
20+
SUPPORT_PREFIX = (
21+
Path(__file__).parent.parent
22+
/ os.getenv("PYTHON_SUPPORT_BASE", default_support_base)
23+
/ "Python.xcframework"
24+
/ PYTHON_CROSS_SLICE
25+
)
26+
27+
28+
###########################################################################
29+
# sys
30+
###########################################################################
31+
32+
def test_sys_platform():
33+
assert sys.platform == PYTHON_CROSS_PLATFORM.lower()
34+
35+
36+
def test_sys_cross_compiling():
37+
assert sys.cross_compiling
38+
39+
40+
def test_sys_multiarch():
41+
assert sys.implementation._multiarch == PYTHON_CROSS_MULTIARCH
42+
43+
44+
def test_sys_base_prefix():
45+
assert Path(sys.base_prefix) == SUPPORT_PREFIX
46+
47+
48+
def test_sys_base_exec_prefix():
49+
assert Path(sys.base_exec_prefix) == SUPPORT_PREFIX
50+
51+
52+
###########################################################################
53+
# platform
54+
###########################################################################
55+
56+
def test_platform_system():
57+
assert platform.system() == PYTHON_CROSS_PLATFORM
58+
59+
60+
###########################################################################
61+
# sysconfig
62+
###########################################################################
63+
64+
def test_sysconfig_get_platform():
65+
parts = sysconfig.get_platform().split("-", 2)
66+
assert parts[0] == PYTHON_CROSS_PLATFORM.lower()
67+
assert parts[2] == PYTHON_CROSS_MULTIARCH
68+
69+
70+
def test_sysconfig_get_sysconfigdata_name():
71+
parts = sysconfig._get_sysconfigdata_name().split("_", 4)
72+
assert parts[3] == PYTHON_CROSS_PLATFORM.lower()
73+
assert parts[4] == PYTHON_CROSS_MULTIARCH
74+
75+
76+
@pytest.mark.parametrize(
77+
"name, prefix",
78+
[
79+
# Paths that should be relative to the support folder
80+
("stdlib", SUPPORT_PREFIX),
81+
("include", SUPPORT_PREFIX),
82+
("platinclude", SUPPORT_PREFIX),
83+
("stdlib", SUPPORT_PREFIX),
84+
# paths that should be relative to the venv
85+
("platstdlib", VENV_PREFIX),
86+
("purelib", VENV_PREFIX),
87+
("platlib", VENV_PREFIX),
88+
("scripts", VENV_PREFIX),
89+
("data", VENV_PREFIX),
90+
]
91+
)
92+
def test_sysconfig_get_paths(name, prefix):
93+
assert sysconfig.get_paths()[name].startswith(str(prefix))

0 commit comments

Comments
 (0)