Skip to content

Commit ce2f834

Browse files
committed
Add tests of cross-platform venv handling.
1 parent 1775bf7 commit ce2f834

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,60 @@ jobs:
210210
# - test_bz2 as a simple test of third party libraries
211211
# - test_ctypes as a test of FFI
212212
python -m testbed run -- test --single-process --rerun -W test_builtin test_grammar test_os test_bz2 test_ctypes
213+
214+
crossenv-test:
215+
name: Cross-platform env test (${{ matrix.platform }})
216+
runs-on: macOS-latest
217+
needs: [ config, build ]
218+
strategy:
219+
fail-fast: false
220+
matrix:
221+
include:
222+
- platform: iOS
223+
slice: ios-arm64_x86_64-simulator
224+
multiarch: arm64-iphonesimulator
225+
- platform: iOS
226+
slice: ios-arm64_x86_64-simulator
227+
multiarch: x86_64-iphonesimulator
228+
- platform: iOS
229+
slice: ios-arm64
230+
multiarch: arm64-iphoneos
231+
232+
steps:
233+
- uses: actions/[email protected]
234+
235+
- name: Get build artifact
236+
uses: actions/[email protected]
237+
with:
238+
pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz
239+
path: dist
240+
merge-multiple: true
241+
242+
- name: Set up Python
243+
uses: actions/[email protected]
244+
with:
245+
# Appending -dev ensures that we can always build the dev release.
246+
# It's a no-op for versions that have been published.
247+
python-version: ${{ needs.config.outputs.PYTHON_VER }}-dev
248+
# Ensure that we *always* use the latest build, not a cached version.
249+
# It's an edge case, but when a new alpha is released, we need to use it ASAP.
250+
check-latest: true
251+
252+
- name: Unpack support package
253+
run: |
254+
mkdir support
255+
cd support
256+
tar zxvf ../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz
257+
258+
- name: Run cross-platform environment test
259+
env:
260+
PYTHON_CROSS_PLATFORM: ${{ matrix.platform }}
261+
PYTHON_CROSS_SLICE: ${{ matrix.slice }}
262+
PYTHON_CROSS_MULTIARCH: ${{ matrix.multiarch }}
263+
run: |
264+
python${{ needs.config.outputs.PYTHON_VER }} -m venv cross-venv
265+
source cross-venv/bin/activate
266+
python -m pip install pytest
267+
# Convert venv into cross-venv
268+
python support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }}/Python.xcframework/${{ matrix.slice }}/platform-config/${{ matrix.multiarch }}/make_cross_venv.py cross-venv
269+
python -m pytest tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ tests/testbed/iOS
1515
*.log
1616
*.gz
1717
*.DS_Store
18+
cross-venv/
19+
temp

tests/test_cross_env.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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

Comments
 (0)