ruff fixed formatting
Code Quality Pipeline / code-quality (pull_request) Failing after 15s
Test Python Package / test (pull_request) Failing after 10s

This commit is contained in:
Brian Bjarke Jensen
2025-09-14 20:09:33 +02:00
parent 0e47db238a
commit 2fa633a44f
3 changed files with 29 additions and 14 deletions
@@ -1,13 +1,17 @@
"""Integration tests for ConnectionAwareInterface."""
import pytest
from python_repositories.interfaces.connection_aware_interface import ConnectionAwareInterface
from python_repositories.interfaces.connection_aware_interface import (
ConnectionAwareInterface,
)
def test_instantiation_fails_when_connect_not_implemented() -> None:
"""Test that instantiation fails if connect is not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement connect."""
def disconnect(self) -> None:
pass
@@ -21,8 +25,10 @@ def test_instantiation_fails_when_connect_not_implemented() -> None:
def test_instantiation_fails_when_disconnect_not_implemented() -> None:
"""Test that instantiation fails if disconnect is not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement disconnect."""
def connect(self) -> None:
pass
@@ -36,8 +42,10 @@ def test_instantiation_fails_when_disconnect_not_implemented() -> None:
def test_instantiation_fails_when_is_connected_not_implemented() -> None:
"""Test that instantiation fails if is_connected is not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement is_connected."""
def connect(self) -> None:
pass
@@ -50,8 +58,10 @@ def test_instantiation_fails_when_is_connected_not_implemented() -> None:
def test_connect_raises_not_implemented_if_not_overwritten() -> None:
"""Test that connect raises NotImplementedError if not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement connect."""
def connect(self) -> None:
super().connect() # type: ignore
@@ -69,8 +79,10 @@ def test_connect_raises_not_implemented_if_not_overwritten() -> None:
def test_disconnect_raises_not_implemented_if_not_overwritten() -> None:
"""Test that disconnect raises NotImplementedError if not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement disconnect."""
def connect(self) -> None:
pass
@@ -88,8 +100,10 @@ def test_disconnect_raises_not_implemented_if_not_overwritten() -> None:
def test_is_connected_raises_not_implemented_if_not_overwritten() -> None:
"""Test that is_connected raises NotImplementedError if not implemented."""
class Incomplete(ConnectionAwareInterface):
"""A class that does not implement is_connected."""
def connect(self) -> None:
pass
@@ -7,8 +7,10 @@ from python_repositories.interfaces.context_aware_interface import ContextAwareI
def test_instantiation_fails_when_enter_not_implemented() -> None:
"""Test that instantiation fails if __enter__ is not implemented."""
class Incomplete(ContextAwareInterface):
"""A class that does not implement __enter__."""
def __exit__(
self, exc_type: type | None, exc_val: object | None, exc_tb: object | None
) -> None:
@@ -20,8 +22,10 @@ def test_instantiation_fails_when_enter_not_implemented() -> None:
def test_instantiation_fails_when_exit_not_implemented() -> None:
"""Test that instantiation fails if __exit__ is not implemented."""
class Incomplete(ContextAwareInterface):
"""A class that does not implement __exit__."""
def __enter__(self) -> Incomplete:
return self
@@ -31,8 +35,10 @@ def test_instantiation_fails_when_exit_not_implemented() -> None:
def test_enter_raises_not_implemented_if_not_overwritten() -> None:
"""Test that __enter__ raises NotImplementedError if not implemented."""
class Incomplete(ContextAwareInterface):
"""A class that does not implement __enter__."""
def __enter__(self) -> Incomplete:
super().__enter__() # type: ignore
return self
@@ -49,8 +55,10 @@ def test_enter_raises_not_implemented_if_not_overwritten() -> None:
def test_exit_raises_not_implemented_if_not_overwritten() -> None:
"""Test that __exit__ raises NotImplementedError if not implemented."""
class Incomplete(ContextAwareInterface):
"""A class that does not implement __exit__."""
def __enter__(self) -> ContextAwareInterface:
return self
+6 -13
View File
@@ -48,26 +48,20 @@ def clear_redis(raw_redis_client: redis.Redis) -> None:
raw_redis_client.flushall()
def test_should_adhere_to_interface(
redis_container: str
) -> None:
def test_should_adhere_to_interface(redis_container: str) -> None:
"""Test that the RedisAdapter adheres to the expected interface."""
# Instantiation fails if interface not adhered to
_ = RedisAdapter()
def test_should_have_logger_when_instantiated(
redis_container: str
) -> None:
def test_should_have_logger_when_instantiated(redis_container: str) -> None:
"""Test that the RedisAdapter has a logger when instantiated."""
adapter = RedisAdapter()
assert hasattr(adapter, "logger")
assert adapter.logger is not None
def test_should_not_be_connected_when_instantiated(
redis_container: str
) -> None:
def test_should_not_be_connected_when_instantiated(redis_container: str) -> None:
"""Test that the RedisAdapter is not connected when instantiated."""
adapter = RedisAdapter()
assert adapter._client is None
@@ -89,7 +83,7 @@ def test_should_raise_connection_error_when_unable_to_connect(
def test_connect_raises_connection_error_when_unable_to_ping(
monkeypatch: pytest.MonkeyPatch
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test that the RedisAdapter raises ConnectionError when ping fails."""
# Set an invalid URI
@@ -98,6 +92,7 @@ def test_connect_raises_connection_error_when_unable_to_ping(
# Monkeypatch redis.Redis.from_url to return a mock client
class MockRedis:
"""A mock Redis client that simulates a failed ping."""
def ping(self) -> bool:
"""Simulate a failed ping."""
return False # Simulate failed ping
@@ -125,9 +120,7 @@ def test_should_log_error_on_exception_during_exit(
assert "Error while exiting context" in caplog.text
def test_should_have_context_manager(
redis_container: str
) -> None:
def test_should_have_context_manager(redis_container: str) -> None:
"""Test that the RedisAdapter can be used as a context manager."""
with RedisAdapter() as adapter:
assert adapter._client is not None