Fix mypy errors from minio 7.2.20 type stubs.
Guard bucket_name before Minio API calls, update S3Error test mocks for the new constructor signature, and add types-redis to the pre-commit mypy hook. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
e3cab5e0b6
commit
0f31170209
@@ -9,6 +9,7 @@ import random
|
||||
import os
|
||||
import logging
|
||||
from minio import S3Error
|
||||
from urllib3.response import BaseHTTPResponse
|
||||
from python_repositories.adapters.minio_adapter import MinioAdapter
|
||||
from python_repositories.interfaces import ObjectRepositoryInterface
|
||||
|
||||
@@ -42,7 +43,7 @@ def same_data(
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def data() -> Generator[BytesIO]:
|
||||
def data() -> Generator[BytesIO, None, None]:
|
||||
"""Provide a sample data bytes for tests."""
|
||||
# Generate random bytes
|
||||
random_bytes = random.randbytes(2**21) # 2 MiB
|
||||
@@ -53,7 +54,7 @@ def data() -> Generator[BytesIO]:
|
||||
def data_in_minio(
|
||||
raw_minio_client: Minio,
|
||||
data: BytesIO,
|
||||
) -> Generator[tuple[str, BytesIO]]:
|
||||
) -> Generator[tuple[str, BytesIO], None, None]:
|
||||
"""Fixture to set up a known value in Minio before each test."""
|
||||
object_name = "test_object"
|
||||
bucket_name = str(os.getenv("MINIO_BUCKET"))
|
||||
@@ -77,7 +78,7 @@ def data_in_minio(
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def minio_adapter() -> Generator[MinioAdapter]:
|
||||
def minio_adapter() -> Generator[MinioAdapter, None, None]:
|
||||
"""Fixture to provide a connected MinioAdapter instance."""
|
||||
adapter = MinioAdapter()
|
||||
adapter.connect()
|
||||
@@ -234,12 +235,12 @@ def test_should_log_warning_when_getting_nonexistent_object(
|
||||
adapter = MinioAdapter()
|
||||
adapter._client = MagicMock(spec=Minio)
|
||||
adapter._client.get_object.side_effect = S3Error(
|
||||
code="NoSuchKey",
|
||||
message="",
|
||||
resource="",
|
||||
request_id="",
|
||||
host_id="",
|
||||
response="",
|
||||
MagicMock(spec=BaseHTTPResponse),
|
||||
"NoSuchKey",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
bucket_name="test-bucket",
|
||||
object_name="missing-object",
|
||||
)
|
||||
@@ -264,12 +265,12 @@ def test_should_log_error_when_getting_with_s3error_other_than_no_such_key(
|
||||
adapter = MinioAdapter()
|
||||
adapter._client = MagicMock(spec=Minio)
|
||||
other_s3error = S3Error(
|
||||
code="UnhandledError",
|
||||
message="",
|
||||
resource="",
|
||||
request_id="",
|
||||
host_id="",
|
||||
response="",
|
||||
MagicMock(spec=BaseHTTPResponse),
|
||||
"UnhandledError",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
bucket_name="test-bucket",
|
||||
object_name="missing-object",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user