Skip to content

Commit

Permalink
chore(types): No partial types in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 21, 2024
1 parent 0ca1803 commit 86280bf
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 29 deletions.
8 changes: 4 additions & 4 deletions bin/make_dependency_update_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from __future__ import annotations

import os
import subprocess
import sys
import textwrap
import time
from pathlib import Path
from subprocess import run

import click


def shell(cmd, *, check: bool, **kwargs):
return run([cmd], shell=True, check=check, **kwargs)
def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]:
return subprocess.run([cmd], shell=True, check=check, **kwargs) # type: ignore[call-overload, no-any-return]


def git_repo_has_changes() -> bool:
Expand Down Expand Up @@ -59,7 +59,7 @@ def main() -> None:
PR generated by `{os.path.basename(__file__)}`.
"""
)
run(
subprocess.run(
[
"gh",
"pr",
Expand Down
6 changes: 4 additions & 2 deletions bin/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def get_projects(
return sorted((Project(item, github) for item in config), reverse=online)


def render_projects(projects: Sequence[Project], *, dest_path: Path, include_info: bool = True):
def render_projects(
projects: Sequence[Project], *, dest_path: Path, include_info: bool = True
) -> str:
io = StringIO()
print = functools.partial(builtins.print, file=io)

Expand Down Expand Up @@ -203,7 +205,7 @@ def insert_projects_table(
projects: Sequence[Project],
input_filename: str,
include_info: bool = True,
):
) -> None:
text = file.read_text()
projects_table = render_projects(projects, include_info=include_info, dest_path=file)

Expand Down
2 changes: 1 addition & 1 deletion bin/update_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VersionTuple:
version_string: str


def git_ls_remote_versions(url) -> list[VersionTuple]:
def git_ls_remote_versions(url: str) -> list[VersionTuple]:
versions: list[VersionTuple] = []
tags = subprocess.run(
["git", "ls-remote", "--tags", url], check=True, text=True, capture_output=True
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,13 @@ warn_unused_configs = true

strict = true
disallow_untyped_defs = false
disallow_incomplete_defs = false

enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = false

[[tool.mypy.overrides]]
module = "cibuildwheel.*"
disallow_untyped_defs = true
disallow_incomplete_defs = true

[[tool.mypy.overrides]]
module = [
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .utils import EMULATED_ARCHS, platform


def pytest_addoption(parser) -> None:
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--run-emulation",
action="store",
Expand Down
2 changes: 1 addition & 1 deletion test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_failing_test(tmp_path):
@pytest.mark.parametrize("test_runner", ["pytest", "unittest"])
def test_bare_pytest_invocation(
tmp_path: Path, capfd: pytest.CaptureFixture[str], test_runner: str
):
) -> None:
"""Check that if a user runs pytest in the the test cwd, it raises a helpful error"""
project_dir = tmp_path / "project"
output_dir = tmp_path / "output"
Expand Down
4 changes: 3 additions & 1 deletion unit_test/linux_build_steps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
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
"""
Expand Down
23 changes: 16 additions & 7 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -301,15 +301,17 @@ 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:
assignment = EnvironmentAssignmentBash("TEST=$(echo 42)")
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"):
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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"):
Expand All @@ -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"}
Expand Down
20 changes: 13 additions & 7 deletions unit_test/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions unit_test/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion unit_test/validate_schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit 86280bf

Please sign in to comment.