chore: use kw_only (Python 3.10+) on most dataclasses (#2422)
* chore: use kw_only (Python 3.10+) on many dataclasses Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix: expose windows file to type checker Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import contextlib
|
||||
import sys
|
||||
from collections.abc import Generator
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import setuptools._distutils.util
|
||||
@@ -10,23 +12,27 @@ from cibuildwheel.errors import FatalError
|
||||
from cibuildwheel.platforms.windows import PythonConfiguration, setup_setuptools_cross_compile
|
||||
|
||||
# monkeypatching os.name is too flaky. E.g. It works on my machine, but fails in pipeline
|
||||
if not sys.platform.startswith("win"):
|
||||
if not sys.platform.startswith("win") and not TYPE_CHECKING:
|
||||
pytest.skip("Windows-only tests", allow_module_level=True)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def patched_environment(monkeypatch: pytest.MonkeyPatch, environment: dict[str, str]):
|
||||
def patched_environment(
|
||||
monkeypatch: pytest.MonkeyPatch, environment: dict[str, str]
|
||||
) -> Generator[None, None, None]:
|
||||
with monkeypatch.context() as mp:
|
||||
for envvar, val in environment.items():
|
||||
mp.setenv(name=envvar, value=val)
|
||||
yield
|
||||
|
||||
|
||||
def test_x86(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
def test_x86(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
arch = "32"
|
||||
environment: dict[str, str] = {}
|
||||
|
||||
configuration = PythonConfiguration("irrelevant", arch, "irrelevant", None)
|
||||
configuration = PythonConfiguration(
|
||||
version="irrelevant", arch=arch, identifier="irrelevant", url=None
|
||||
)
|
||||
|
||||
setup_setuptools_cross_compile(tmp_path, configuration, tmp_path, environment)
|
||||
with patched_environment(monkeypatch, environment):
|
||||
@@ -36,11 +42,13 @@ def test_x86(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
assert target_platform == "win32"
|
||||
|
||||
|
||||
def test_x64(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
def test_x64(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
arch = "64"
|
||||
environment: dict[str, str] = {}
|
||||
|
||||
configuration = PythonConfiguration("irrelevant", arch, "irrelevant", None)
|
||||
configuration = PythonConfiguration(
|
||||
version="irrelevant", arch=arch, identifier="irrelevant", url=None
|
||||
)
|
||||
|
||||
setup_setuptools_cross_compile(tmp_path, configuration, tmp_path, environment)
|
||||
with patched_environment(monkeypatch, environment):
|
||||
@@ -53,11 +61,13 @@ def test_x64(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
@pytest.mark.skipif(
|
||||
detect_ci_provider() == CIProvider.azure_pipelines, reason="arm64 not recognised on azure"
|
||||
)
|
||||
def test_arm(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
def test_arm(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
arch = "ARM64"
|
||||
environment: dict[str, str] = {}
|
||||
|
||||
configuration = PythonConfiguration("irrelevant", arch, "irrelevant", None)
|
||||
configuration = PythonConfiguration(
|
||||
version="irrelevant", arch=arch, identifier="irrelevant", url=None
|
||||
)
|
||||
|
||||
setup_setuptools_cross_compile(tmp_path, configuration, tmp_path, environment)
|
||||
with patched_environment(monkeypatch, environment):
|
||||
@@ -67,21 +77,25 @@ def test_arm(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
assert target_platform == "win-arm64"
|
||||
|
||||
|
||||
def test_env_set(tmp_path: Path):
|
||||
def test_env_set(tmp_path: Path) -> None:
|
||||
arch = "32"
|
||||
environment = {"VSCMD_ARG_TGT_ARCH": "x64"}
|
||||
|
||||
configuration = PythonConfiguration("irrelevant", arch, "irrelevant", None)
|
||||
configuration = PythonConfiguration(
|
||||
version="irrelevant", arch=arch, identifier="irrelevant", url=None
|
||||
)
|
||||
|
||||
with pytest.raises(FatalError, match="VSCMD_ARG_TGT_ARCH"):
|
||||
setup_setuptools_cross_compile(tmp_path, configuration, tmp_path, environment)
|
||||
|
||||
|
||||
def test_env_blank(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
def test_env_blank(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
arch = "32"
|
||||
environment = {"VSCMD_ARG_TGT_ARCH": ""}
|
||||
|
||||
configuration = PythonConfiguration("irrelevant", arch, "irrelevant", None)
|
||||
configuration = PythonConfiguration(
|
||||
version="irrelevant", arch=arch, identifier="irrelevant", url=None
|
||||
)
|
||||
|
||||
setup_setuptools_cross_compile(tmp_path, configuration, tmp_path, environment)
|
||||
with patched_environment(monkeypatch, environment):
|
||||
|
||||
Reference in New Issue
Block a user