|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import sys |
| 4 | +import sysconfig |
4 | 5 | from textwrap import dedent |
5 | 6 | from typing import TYPE_CHECKING |
6 | 7 |
|
@@ -1070,3 +1071,50 @@ def test_config_in_toml_replace_ref_command(tox_project: ToxProjectCreator) -> N |
1070 | 1071 | assert "python" in outcome.out |
1071 | 1072 | assert "pip" in outcome.out |
1072 | 1073 | assert "freeze" in outcome.out |
| 1074 | + |
| 1075 | + |
| 1076 | +def test_toml_machine_isa_does_not_override_explicit_env_factor(tox_project: ToxProjectCreator) -> None: |
| 1077 | + """Regression test for #3903: explicit ISA in env name takes precedence over machine ISA in TOML.""" |
| 1078 | + parts = sysconfig.get_platform().rsplit("-", 1) |
| 1079 | + if len(parts) < 2: |
| 1080 | + pytest.skip("sysconfig.get_platform() has no machine component") |
| 1081 | + machine = parts[-1] |
| 1082 | + other_isa = "x86_64" if machine != "x86_64" else "arm64" |
| 1083 | + |
| 1084 | + project = tox_project({ |
| 1085 | + "pyproject.toml": dedent(f""" |
| 1086 | + [tool.tox.env_run_base] |
| 1087 | + package = "skip" |
| 1088 | + description = {{ replace = "if", condition = "factor.{machine}", then = "{machine}_val", \ |
| 1089 | +else = {{ replace = "if", condition = "factor.{other_isa}", then = "{other_isa}_val", else = "unknown" }} }} |
| 1090 | +
|
| 1091 | + [tool.tox.env.py39-{other_isa}] |
| 1092 | + """), |
| 1093 | + }) |
| 1094 | + # Env name contains other_isa, so only other_isa condition should match, not machine ISA. |
| 1095 | + outcome = project.run("c", "-e", f"py39-{other_isa}", "-k", "description") |
| 1096 | + outcome.assert_success() |
| 1097 | + assert f"{other_isa}_val" in outcome.out |
| 1098 | + assert f"{machine}_val" not in outcome.out |
| 1099 | + |
| 1100 | + |
| 1101 | +def test_toml_machine_isa_implicit_when_no_env_isa(tox_project: ToxProjectCreator) -> None: |
| 1102 | + """Machine ISA is added implicitly to TOML factors when no ISA factor is in the env name.""" |
| 1103 | + parts = sysconfig.get_platform().rsplit("-", 1) |
| 1104 | + if len(parts) < 2: |
| 1105 | + pytest.skip("sysconfig.get_platform() has no machine component") |
| 1106 | + machine = parts[-1] |
| 1107 | + |
| 1108 | + project = tox_project({ |
| 1109 | + "pyproject.toml": dedent(f""" |
| 1110 | + [tool.tox.env_run_base] |
| 1111 | + package = "skip" |
| 1112 | + description = {{ replace = "if", condition = "factor.{machine}", then = "matched", else = "no-match" }} |
| 1113 | +
|
| 1114 | + [tool.tox.env.py39] |
| 1115 | + """), |
| 1116 | + }) |
| 1117 | + # No ISA in env name, so machine ISA should be added implicitly. |
| 1118 | + outcome = project.run("c", "-e", "py39", "-k", "description") |
| 1119 | + outcome.assert_success() |
| 1120 | + assert "matched" in outcome.out |
0 commit comments