Add typing information, 2/n (#1178)

* Add typing to Docker Stack modules. Clean modules up.

* Add typing to Docker Swarm modules.

* Add typing to unit tests.

* Add more typing.

* Add ignore.txt entries.
This commit is contained in:
Felix Fontein
2025-10-25 01:16:04 +02:00
committed by GitHub
parent 3350283bcc
commit 6ad4bfcd40
84 changed files with 1496 additions and 1161 deletions
+17 -10
View File
@@ -4,6 +4,8 @@
from __future__ import annotations
import typing as t
import pytest
from ansible_collections.community.docker.plugins.module_utils._image_archive import (
@@ -19,19 +21,24 @@ from ..test_support.docker_image_archive_stubbing import (
)
def assert_no_logging(msg):
if t.TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path
def assert_no_logging(msg: str) -> t.NoReturn:
raise AssertionError(f"Should not have logged anything but logged {msg}")
def capture_logging(messages):
def capture(msg):
def capture_logging(messages: list[str]) -> Callable[[str], None]:
def capture(msg: str) -> None:
messages.append(msg)
return capture
@pytest.fixture
def tar_file_name(tmpdir):
def tar_file_name(tmpdir: t.Any) -> str:
"""
Return the name of a non-existing tar file in an existing temporary directory.
"""
@@ -39,7 +46,7 @@ def tar_file_name(tmpdir):
return tmpdir.join("foo.tar")
def test_archived_image_action_when_missing(tar_file_name):
def test_archived_image_action_when_missing(tar_file_name: str) -> None:
fake_name = "a:latest"
fake_id = "a1"
@@ -52,7 +59,7 @@ def test_archived_image_action_when_missing(tar_file_name):
assert actual == expected
def test_archived_image_action_when_current(tar_file_name):
def test_archived_image_action_when_current(tar_file_name: str) -> None:
fake_name = "b:latest"
fake_id = "b2"
@@ -65,7 +72,7 @@ def test_archived_image_action_when_current(tar_file_name):
assert actual is None
def test_archived_image_action_when_invalid(tar_file_name):
def test_archived_image_action_when_invalid(tar_file_name: str) -> None:
fake_name = "c:1.2.3"
fake_id = "c3"
@@ -73,7 +80,7 @@ def test_archived_image_action_when_invalid(tar_file_name):
expected = f"Archived image {fake_name} to {tar_file_name}, overwriting an unreadable archive file"
actual_log = []
actual_log: list[str] = []
actual = ImageManager.archived_image_action(
capture_logging(actual_log), tar_file_name, fake_name, api_image_id(fake_id)
)
@@ -84,7 +91,7 @@ def test_archived_image_action_when_invalid(tar_file_name):
assert actual_log[0].startswith("Unable to extract manifest summary from archive")
def test_archived_image_action_when_obsolete_by_id(tar_file_name):
def test_archived_image_action_when_obsolete_by_id(tar_file_name: str) -> None:
fake_name = "d:0.0.1"
old_id = "e5"
new_id = "d4"
@@ -99,7 +106,7 @@ def test_archived_image_action_when_obsolete_by_id(tar_file_name):
assert actual == expected
def test_archived_image_action_when_obsolete_by_name(tar_file_name):
def test_archived_image_action_when_obsolete_by_name(tar_file_name: str) -> None:
old_name = "hi"
new_name = "d:0.0.1"
fake_id = "d4"