mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
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:
@@ -5,6 +5,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tarfile
|
||||
import typing as t
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -22,7 +23,7 @@ from ..test_support.docker_image_archive_stubbing import (
|
||||
|
||||
|
||||
@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.
|
||||
"""
|
||||
@@ -34,11 +35,11 @@ def tar_file_name(tmpdir):
|
||||
@pytest.mark.parametrize(
|
||||
"expected, value", [("sha256:foo", "foo"), ("sha256:bar", "bar")]
|
||||
)
|
||||
def test_api_image_id_from_archive_id(expected, value):
|
||||
def test_api_image_id_from_archive_id(expected: str, value: str) -> None:
|
||||
assert api_image_id(value) == expected
|
||||
|
||||
|
||||
def test_archived_image_manifest_extracts(tar_file_name):
|
||||
def test_archived_image_manifest_extracts(tar_file_name: str) -> None:
|
||||
expected_id = "abcde12345"
|
||||
expected_tags = ["foo:latest", "bar:v1"]
|
||||
|
||||
@@ -46,17 +47,20 @@ def test_archived_image_manifest_extracts(tar_file_name):
|
||||
|
||||
actual = archived_image_manifest(tar_file_name)
|
||||
|
||||
assert actual is not None
|
||||
assert actual.image_id == expected_id
|
||||
assert actual.repo_tags == expected_tags
|
||||
|
||||
|
||||
def test_archived_image_manifest_extracts_nothing_when_file_not_present(tar_file_name):
|
||||
def test_archived_image_manifest_extracts_nothing_when_file_not_present(
|
||||
tar_file_name: str,
|
||||
) -> None:
|
||||
image_id = archived_image_manifest(tar_file_name)
|
||||
|
||||
assert image_id is None
|
||||
|
||||
|
||||
def test_archived_image_manifest_raises_when_file_not_a_tar():
|
||||
def test_archived_image_manifest_raises_when_file_not_a_tar() -> None:
|
||||
try:
|
||||
archived_image_manifest(__file__)
|
||||
raise AssertionError()
|
||||
@@ -65,7 +69,9 @@ def test_archived_image_manifest_raises_when_file_not_a_tar():
|
||||
assert str(__file__) in str(e)
|
||||
|
||||
|
||||
def test_archived_image_manifest_raises_when_tar_missing_manifest(tar_file_name):
|
||||
def test_archived_image_manifest_raises_when_tar_missing_manifest(
|
||||
tar_file_name: str,
|
||||
) -> None:
|
||||
write_irrelevant_tar(tar_file_name)
|
||||
|
||||
try:
|
||||
@@ -76,7 +82,9 @@ def test_archived_image_manifest_raises_when_tar_missing_manifest(tar_file_name)
|
||||
assert "manifest.json" in str(e.__cause__)
|
||||
|
||||
|
||||
def test_archived_image_manifest_raises_when_manifest_missing_id(tar_file_name):
|
||||
def test_archived_image_manifest_raises_when_manifest_missing_id(
|
||||
tar_file_name: str,
|
||||
) -> None:
|
||||
manifest = [{"foo": "bar"}]
|
||||
|
||||
write_imitation_archive_with_manifest(tar_file_name, manifest)
|
||||
|
||||
Reference in New Issue
Block a user