ruff fixed formatting
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
"""Integration tests for ConnectionAwareInterface."""
|
"""Integration tests for ConnectionAwareInterface."""
|
||||||
|
|
||||||
import pytest
|
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:
|
def test_instantiation_fails_when_connect_not_implemented() -> None:
|
||||||
"""Test that instantiation fails if connect is not implemented."""
|
"""Test that instantiation fails if connect is not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement connect."""
|
"""A class that does not implement connect."""
|
||||||
|
|
||||||
def disconnect(self) -> None:
|
def disconnect(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -21,8 +25,10 @@ def test_instantiation_fails_when_connect_not_implemented() -> None:
|
|||||||
|
|
||||||
def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
||||||
"""Test that instantiation fails if disconnect is not implemented."""
|
"""Test that instantiation fails if disconnect is not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement disconnect."""
|
"""A class that does not implement disconnect."""
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -36,8 +42,10 @@ def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
|||||||
|
|
||||||
def test_instantiation_fails_when_is_connected_not_implemented() -> None:
|
def test_instantiation_fails_when_is_connected_not_implemented() -> None:
|
||||||
"""Test that instantiation fails if is_connected is not implemented."""
|
"""Test that instantiation fails if is_connected is not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement is_connected."""
|
"""A class that does not implement is_connected."""
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
pass
|
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:
|
def test_connect_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
"""Test that connect raises NotImplementedError if not implemented."""
|
"""Test that connect raises NotImplementedError if not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement connect."""
|
"""A class that does not implement connect."""
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
super().connect() # type: ignore
|
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:
|
def test_disconnect_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
"""Test that disconnect raises NotImplementedError if not implemented."""
|
"""Test that disconnect raises NotImplementedError if not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement disconnect."""
|
"""A class that does not implement disconnect."""
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
pass
|
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:
|
def test_is_connected_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
"""Test that is_connected raises NotImplementedError if not implemented."""
|
"""Test that is_connected raises NotImplementedError if not implemented."""
|
||||||
|
|
||||||
class Incomplete(ConnectionAwareInterface):
|
class Incomplete(ConnectionAwareInterface):
|
||||||
"""A class that does not implement is_connected."""
|
"""A class that does not implement is_connected."""
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ from python_repositories.interfaces.context_aware_interface import ContextAwareI
|
|||||||
|
|
||||||
def test_instantiation_fails_when_enter_not_implemented() -> None:
|
def test_instantiation_fails_when_enter_not_implemented() -> None:
|
||||||
"""Test that instantiation fails if __enter__ is not implemented."""
|
"""Test that instantiation fails if __enter__ is not implemented."""
|
||||||
|
|
||||||
class Incomplete(ContextAwareInterface):
|
class Incomplete(ContextAwareInterface):
|
||||||
"""A class that does not implement __enter__."""
|
"""A class that does not implement __enter__."""
|
||||||
|
|
||||||
def __exit__(
|
def __exit__(
|
||||||
self, exc_type: type | None, exc_val: object | None, exc_tb: object | None
|
self, exc_type: type | None, exc_val: object | None, exc_tb: object | None
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -20,8 +22,10 @@ def test_instantiation_fails_when_enter_not_implemented() -> None:
|
|||||||
|
|
||||||
def test_instantiation_fails_when_exit_not_implemented() -> None:
|
def test_instantiation_fails_when_exit_not_implemented() -> None:
|
||||||
"""Test that instantiation fails if __exit__ is not implemented."""
|
"""Test that instantiation fails if __exit__ is not implemented."""
|
||||||
|
|
||||||
class Incomplete(ContextAwareInterface):
|
class Incomplete(ContextAwareInterface):
|
||||||
"""A class that does not implement __exit__."""
|
"""A class that does not implement __exit__."""
|
||||||
|
|
||||||
def __enter__(self) -> Incomplete:
|
def __enter__(self) -> Incomplete:
|
||||||
return self
|
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:
|
def test_enter_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
"""Test that __enter__ raises NotImplementedError if not implemented."""
|
"""Test that __enter__ raises NotImplementedError if not implemented."""
|
||||||
|
|
||||||
class Incomplete(ContextAwareInterface):
|
class Incomplete(ContextAwareInterface):
|
||||||
"""A class that does not implement __enter__."""
|
"""A class that does not implement __enter__."""
|
||||||
|
|
||||||
def __enter__(self) -> Incomplete:
|
def __enter__(self) -> Incomplete:
|
||||||
super().__enter__() # type: ignore
|
super().__enter__() # type: ignore
|
||||||
return self
|
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:
|
def test_exit_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
"""Test that __exit__ raises NotImplementedError if not implemented."""
|
"""Test that __exit__ raises NotImplementedError if not implemented."""
|
||||||
|
|
||||||
class Incomplete(ContextAwareInterface):
|
class Incomplete(ContextAwareInterface):
|
||||||
"""A class that does not implement __exit__."""
|
"""A class that does not implement __exit__."""
|
||||||
|
|
||||||
def __enter__(self) -> ContextAwareInterface:
|
def __enter__(self) -> ContextAwareInterface:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|||||||
@@ -48,26 +48,20 @@ def clear_redis(raw_redis_client: redis.Redis) -> None:
|
|||||||
raw_redis_client.flushall()
|
raw_redis_client.flushall()
|
||||||
|
|
||||||
|
|
||||||
def test_should_adhere_to_interface(
|
def test_should_adhere_to_interface(redis_container: str) -> None:
|
||||||
redis_container: str
|
|
||||||
) -> None:
|
|
||||||
"""Test that the RedisAdapter adheres to the expected interface."""
|
"""Test that the RedisAdapter adheres to the expected interface."""
|
||||||
# Instantiation fails if interface not adhered to
|
# Instantiation fails if interface not adhered to
|
||||||
_ = RedisAdapter()
|
_ = RedisAdapter()
|
||||||
|
|
||||||
|
|
||||||
def test_should_have_logger_when_instantiated(
|
def test_should_have_logger_when_instantiated(redis_container: str) -> None:
|
||||||
redis_container: str
|
|
||||||
) -> None:
|
|
||||||
"""Test that the RedisAdapter has a logger when instantiated."""
|
"""Test that the RedisAdapter has a logger when instantiated."""
|
||||||
adapter = RedisAdapter()
|
adapter = RedisAdapter()
|
||||||
assert hasattr(adapter, "logger")
|
assert hasattr(adapter, "logger")
|
||||||
assert adapter.logger is not None
|
assert adapter.logger is not None
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_be_connected_when_instantiated(
|
def test_should_not_be_connected_when_instantiated(redis_container: str) -> None:
|
||||||
redis_container: str
|
|
||||||
) -> None:
|
|
||||||
"""Test that the RedisAdapter is not connected when instantiated."""
|
"""Test that the RedisAdapter is not connected when instantiated."""
|
||||||
adapter = RedisAdapter()
|
adapter = RedisAdapter()
|
||||||
assert adapter._client is None
|
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(
|
def test_connect_raises_connection_error_when_unable_to_ping(
|
||||||
monkeypatch: pytest.MonkeyPatch
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that the RedisAdapter raises ConnectionError when ping fails."""
|
"""Test that the RedisAdapter raises ConnectionError when ping fails."""
|
||||||
# Set an invalid URI
|
# 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
|
# Monkeypatch redis.Redis.from_url to return a mock client
|
||||||
class MockRedis:
|
class MockRedis:
|
||||||
"""A mock Redis client that simulates a failed ping."""
|
"""A mock Redis client that simulates a failed ping."""
|
||||||
|
|
||||||
def ping(self) -> bool:
|
def ping(self) -> bool:
|
||||||
"""Simulate a failed ping."""
|
"""Simulate a failed ping."""
|
||||||
return False # Simulate 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
|
assert "Error while exiting context" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
def test_should_have_context_manager(
|
def test_should_have_context_manager(redis_container: str) -> None:
|
||||||
redis_container: str
|
|
||||||
) -> None:
|
|
||||||
"""Test that the RedisAdapter can be used as a context manager."""
|
"""Test that the RedisAdapter can be used as a context manager."""
|
||||||
with RedisAdapter() as adapter:
|
with RedisAdapter() as adapter:
|
||||||
assert adapter._client is not None
|
assert adapter._client is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user