chore: stricter mypy (#2053)

* chore: improve mypy

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* chore(types): type functions in tests

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* chore(types): No partial types in tests

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2024-10-22 10:16:59 -04:00
committed by GitHub
parent b4d1e17765
commit b98602705f
27 changed files with 131 additions and 111 deletions
+6 -4
View File
@@ -4,12 +4,14 @@ import textwrap
from pathlib import Path
from pprint import pprint
import pytest
import cibuildwheel.linux
from cibuildwheel.oci_container import OCIContainerEngineConfig
from cibuildwheel.options import CommandLineArguments, Options
def test_linux_container_split(tmp_path: Path, monkeypatch):
def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""
Tests splitting linux builds by container image, container engine, and before_all
"""
@@ -53,13 +55,13 @@ def test_linux_container_split(tmp_path: Path, monkeypatch):
build_steps = list(cibuildwheel.linux.get_build_steps(options, python_configurations))
# helper functions to extract test info
def identifiers(step):
def identifiers(step: cibuildwheel.linux.BuildStep) -> list[str]:
return [c.identifier for c in step.platform_configs]
def before_alls(step):
def before_alls(step: cibuildwheel.linux.BuildStep) -> list[str]:
return [options.build_options(c.identifier).before_all for c in step.platform_configs]
def container_engines(step):
def container_engines(step: cibuildwheel.linux.BuildStep) -> list[OCIContainerEngineConfig]:
return [options.build_options(c.identifier).container_engine for c in step.platform_configs]
pprint(build_steps)
+4 -4
View File
@@ -12,12 +12,12 @@ from cibuildwheel import linux, macos, util, windows
class ArgsInterceptor:
def __init__(self):
def __init__(self) -> None:
self.call_count = 0
self.args = None
self.kwargs = None
self.args: tuple[object, ...] | None = None
self.kwargs: dict[str, object] | None = None
def __call__(self, *args, **kwargs):
def __call__(self, *args: object, **kwargs: object) -> None:
self.call_count += 1
self.args = args
self.kwargs = kwargs
+1 -1
View File
@@ -119,7 +119,7 @@ def test_manylinux_images(
assert build_options.manylinux_images is None
def get_default_repair_command(platform):
def get_default_repair_command(platform: str) -> str:
if platform == "linux":
return "auditwheel repair -w {dest_dir} {wheel}"
elif platform == "macos":
+16 -7
View File
@@ -239,7 +239,7 @@ def test_binary_output(container_engine):
assert output == binary_data_string
def test_file_operation(tmp_path: Path, container_engine):
def test_file_operation(tmp_path: Path, container_engine: OCIContainerEngineConfig) -> None:
with OCIContainer(
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
) as container:
@@ -259,7 +259,7 @@ def test_file_operation(tmp_path: Path, container_engine):
assert test_binary_data == bytes(output, encoding="utf8", errors="surrogateescape")
def test_dir_operations(tmp_path: Path, container_engine):
def test_dir_operations(tmp_path: Path, container_engine: OCIContainerEngineConfig) -> None:
with OCIContainer(
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
) as container:
@@ -301,7 +301,7 @@ def test_dir_operations(tmp_path: Path, container_engine):
assert test_binary_data == (new_test_dir / "test.dat").read_bytes()
def test_environment_executor(container_engine):
def test_environment_executor(container_engine: OCIContainerEngineConfig) -> None:
with OCIContainer(
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
) as container:
@@ -309,7 +309,9 @@ def test_environment_executor(container_engine):
assert assignment.evaluated_value({}, container.environment_executor) == "42"
def test_podman_vfs(tmp_path: Path, monkeypatch, container_engine):
def test_podman_vfs(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, container_engine: OCIContainerEngineConfig
) -> None:
if container_engine.name != "podman":
pytest.skip("only runs with podman")
if sys.platform.startswith("darwin"):
@@ -391,7 +393,7 @@ def test_podman_vfs(tmp_path: Path, monkeypatch, container_engine):
subprocess.run(["podman", "unshare", "rm", "-rf", vfs_path], check=True)
def test_create_args_volume(tmp_path: Path, container_engine):
def test_create_args_volume(tmp_path: Path, container_engine: OCIContainerEngineConfig) -> None:
if container_engine.name != "docker":
pytest.skip("only runs with docker")
@@ -513,7 +515,12 @@ def test_enforce_32_bit(container_engine):
("{name}; disable_host_mount: true", False),
],
)
def test_disable_host_mount(tmp_path: Path, container_engine, config, should_have_host_mount):
def test_disable_host_mount(
tmp_path: Path,
container_engine: OCIContainerEngineConfig,
config: str,
should_have_host_mount: bool,
) -> None:
if detect_ci_provider() in {CIProvider.circle_ci, CIProvider.gitlab}:
pytest.skip("Skipping test because docker on this platform does not support host mounts")
if sys.platform.startswith("darwin"):
@@ -536,7 +543,9 @@ def test_disable_host_mount(tmp_path: Path, container_engine, config, should_hav
@pytest.mark.parametrize("platform", list(OCIPlatform))
def test_local_image(container_engine, platform, tmp_path: Path):
def test_local_image(
container_engine: OCIContainerEngineConfig, platform: OCIPlatform, tmp_path: Path
) -> None:
if (
detect_ci_provider() in {CIProvider.travis_ci}
and pm in {"s390x", "ppc64le"}
+13 -7
View File
@@ -178,7 +178,7 @@ def test_toml_environment_evil(tmp_path, env_var_value):
(r'TEST_VAR="before\\$after"', "before$after"),
],
)
def test_toml_environment_quoting(tmp_path: Path, toml_assignment, result_value):
def test_toml_environment_quoting(tmp_path: Path, toml_assignment: str, result_value: str) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
@@ -255,8 +255,12 @@ def test_toml_environment_quoting(tmp_path: Path, toml_assignment, result_value)
],
)
def test_container_engine_option(
tmp_path: Path, toml_assignment, result_name, result_create_args, result_disable_host_mount
):
tmp_path: Path,
toml_assignment: str,
result_name: str,
result_create_args: tuple[str, ...],
result_disable_host_mount: bool,
) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
@@ -326,7 +330,9 @@ def test_environment_pass_references():
),
],
)
def test_build_frontend_option(tmp_path: Path, toml_assignment, result_name, result_args):
def test_build_frontend_option(
tmp_path: Path, toml_assignment: str, result_name: str, result_args: list[str]
) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
@@ -350,7 +356,7 @@ def test_build_frontend_option(tmp_path: Path, toml_assignment, result_name, res
assert parsed_build_frontend is None
def test_override_inherit_environment(tmp_path: Path):
def test_override_inherit_environment(tmp_path: Path) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
@@ -385,7 +391,7 @@ def test_override_inherit_environment(tmp_path: Path):
}
def test_override_inherit_environment_with_references(tmp_path: Path):
def test_override_inherit_environment_with_references(tmp_path: Path) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
@@ -434,7 +440,7 @@ def test_override_inherit_environment_with_references(tmp_path: Path):
)
def test_free_threaded_support(
tmp_path: Path, toml_assignment: str, env: dict[str, str], expected_result: bool
):
) -> None:
args = CommandLineArguments.defaults()
args.package_dir = tmp_path
+2 -2
View File
@@ -76,7 +76,7 @@ def test_prepare_command():
("foo-0.1-py38-none-win_amd64.whl", "pp310-win_amd64"),
],
)
def test_find_compatible_wheel_found(wheel: str, identifier: str):
def test_find_compatible_wheel_found(wheel: str, identifier: str) -> None:
wheel_ = PurePath(wheel)
found = find_compatible_wheel([wheel_], identifier)
assert found is wheel_
@@ -96,7 +96,7 @@ def test_find_compatible_wheel_found(wheel: str, identifier: str):
("foo-0.1-cp38-cp38-win_amd64.whl", "cp310-win_amd64"),
],
)
def test_find_compatible_wheel_not_found(wheel: str, identifier: str):
def test_find_compatible_wheel_not_found(wheel: str, identifier: str) -> None:
assert find_compatible_wheel([PurePath(wheel)], identifier) is None
+1 -1
View File
@@ -45,7 +45,7 @@ def test_validate_container_engine():
@pytest.mark.parametrize("platform", ["macos", "windows"])
def test_validate_bad_container_engine(platform: str):
def test_validate_bad_container_engine(platform: str) -> None:
"""
container-engine is not a valid option for macos or windows
"""
+1 -1
View File
@@ -27,7 +27,7 @@ def test_no_printout_on_error(tmp_path, capsys):
tmp_path.joinpath("example.1").touch()
raise RuntimeError()
captured = capsys.readouterr() # type: ignore[unreachable]
captured = capsys.readouterr()
assert captured.err == ""
assert "example.0" not in captured.out