|
1 | | -# (c) 2022-2025 Michał Górny |
| 1 | +# (c) 2022-2026 Michał Górny |
2 | 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
3 | 3 |
|
4 | 4 | import contextlib |
5 | 5 | import importlib.machinery |
6 | 6 | import importlib.util |
7 | 7 | import os |
8 | 8 | import pathlib |
| 9 | +import shutil |
| 10 | +import sys |
9 | 11 | import sysconfig |
10 | 12 | import typing |
11 | 13 |
|
| 14 | +import packaging.tags |
12 | 15 | import pytest |
13 | 16 |
|
14 | 17 | from gpep517 import __version__ |
@@ -379,3 +382,49 @@ def test_install_symlink_chain(tmp_path, |
379 | 382 | assert expected_links == {path: tmp_path.joinpath(path).readlink() |
380 | 383 | for path, path_data in expected.items() |
381 | 384 | if path_data is not None and path_data[1]} |
| 385 | + |
| 386 | + |
| 387 | +BEST_TAG = next(packaging.tags.sys_tags()) |
| 388 | +FREETHREADING = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) |
| 389 | +IS_CPYTHON = sys.implementation.name == "cpython" |
| 390 | + |
| 391 | +@pytest.mark.parametrize( |
| 392 | + ("wheel_name", "expected"), |
| 393 | + [ |
| 394 | + ("test-1-py3-none-any.whl", True), |
| 395 | + ("test-1-py2.py3-none-any.whl", True), |
| 396 | + ("test-1-py38-none-any.whl", sys.version_info >= (3, 8)), |
| 397 | + (f"test-1-{BEST_TAG}.whl", True), |
| 398 | + (f"test-1-{BEST_TAG.interpreter}-none-any.whl", IS_CPYTHON), |
| 399 | + (f"test-1-{BEST_TAG.interpreter}-{BEST_TAG.abi}-any.whl", False), |
| 400 | + (f"test-1-{BEST_TAG.interpreter}-abi3-any.whl", False), |
| 401 | + (f"test-1-py3-none-{BEST_TAG.platform}.whl", True), |
| 402 | + (f"test-1-py38-none-{BEST_TAG.platform}.whl", sys.version_info >= (3, 8)), |
| 403 | + (f"test-1-{BEST_TAG.interpreter}-none-{BEST_TAG.platform}.whl", True), |
| 404 | + (f"test-1-{BEST_TAG.interpreter}-abi3-{BEST_TAG.platform}.whl", IS_CPYTHON and not FREETHREADING), |
| 405 | + (f"test-1-{BEST_TAG.interpreter}-abi3t-{BEST_TAG.platform}.whl", IS_CPYTHON and FREETHREADING and sys.version_info >= (3, 15)), |
| 406 | + (f"test-1-{BEST_TAG.interpreter}-abi3.abi3t-{BEST_TAG.platform}.whl", IS_CPYTHON), |
| 407 | + (f"test-1-cp38-abi3-{BEST_TAG.platform}.whl", IS_CPYTHON and sys.version_info >= (3, 8) and not FREETHREADING), |
| 408 | + (f"test-1-cp38-abi3.abi3t-{BEST_TAG.platform}.whl", IS_CPYTHON and sys.version_info >= (3, 8)), |
| 409 | + (f"test-1-cp315-abi3.abi3t-{BEST_TAG.platform}.whl", IS_CPYTHON and sys.version_info >= (3, 15)), |
| 410 | + (f"test-1-py3-none-win32.whl", sysconfig.get_platform() == "win32"), |
| 411 | + (f"test-1-py3-none-linux_x86_64.whl", sysconfig.get_platform() == "linux-x86_64"), |
| 412 | + ] |
| 413 | +) |
| 414 | +def test_verify_tags(tmp_path, |
| 415 | + wheel_name: str, |
| 416 | + expected: bool, |
| 417 | + ) -> None: |
| 418 | + shutil.copy("test/test-pkg/dist/test-1-py3-none-any.whl", |
| 419 | + tmp_path / wheel_name) |
| 420 | + |
| 421 | + ctx_mgr = ( contextlib.nullcontext() if expected else |
| 422 | + pytest.raises(RuntimeError, |
| 423 | + match="not compatible with the system")) |
| 424 | + args = (["", "install-wheel", |
| 425 | + "--destdir", str(tmp_path), |
| 426 | + "--verify-tags", |
| 427 | + str(tmp_path / wheel_name)] |
| 428 | + ) |
| 429 | + with ctx_mgr: |
| 430 | + assert 0 == main(args) |
0 commit comments