fuxed mypy issues
This commit is contained in:
@@ -53,6 +53,10 @@ show_error_codes = true # show error codes in output
|
|||||||
explicit_package_bases = true # reduce risk of import confusion
|
explicit_package_bases = true # reduce risk of import confusion
|
||||||
namespace_packages = true # enable namespace packages
|
namespace_packages = true # enable namespace packages
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = "testcontainers.*"
|
||||||
|
ignore_missing_imports = true
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = [
|
dev = [
|
||||||
"mypy>=1.17.1",
|
"mypy>=1.17.1",
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def test_instantiation_fails_when_connect_not_implemented() -> None:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_ = Incomplete()
|
_ = Incomplete() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
||||||
@@ -31,7 +31,7 @@ def test_instantiation_fails_when_disconnect_not_implemented() -> None:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_ = Incomplete()
|
_ = Incomplete() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_instantiation_fails_when_is_connected_not_implemented() -> None:
|
def test_instantiation_fails_when_is_connected_not_implemented() -> None:
|
||||||
@@ -45,7 +45,7 @@ def test_instantiation_fails_when_is_connected_not_implemented() -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_ = Incomplete()
|
_ = Incomplete() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_connect_raises_not_implemented_if_not_overwritten() -> None:
|
def test_connect_raises_not_implemented_if_not_overwritten() -> None:
|
||||||
@@ -53,7 +53,7 @@ def test_connect_raises_not_implemented_if_not_overwritten() -> None:
|
|||||||
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()
|
super().connect() # type: ignore
|
||||||
|
|
||||||
def disconnect(self) -> None:
|
def disconnect(self) -> None:
|
||||||
pass
|
pass
|
||||||
@@ -75,7 +75,7 @@ def test_disconnect_raises_not_implemented_if_not_overwritten() -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def disconnect(self) -> None:
|
def disconnect(self) -> None:
|
||||||
super().disconnect()
|
super().disconnect() # type: ignore
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
@@ -98,7 +98,7 @@ def test_is_connected_raises_not_implemented_if_not_overwritten() -> None:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
return super().is_connected
|
return super().is_connected # type: ignore
|
||||||
|
|
||||||
instance = Incomplete()
|
instance = Incomplete()
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Integration tests for ContextAwareInterface."""
|
"""Integration tests for ContextAwareInterface."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import pytest
|
import pytest
|
||||||
from python_repositories.interfaces.context_aware_interface import ContextAwareInterface
|
from python_repositories.interfaces.context_aware_interface import ContextAwareInterface
|
||||||
|
|
||||||
@@ -14,26 +15,27 @@ def test_instantiation_fails_when_enter_not_implemented() -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_ = Incomplete()
|
_ = Incomplete() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
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) -> ContextAwareInterface:
|
def __enter__(self) -> Incomplete:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_ = Incomplete()
|
_ = Incomplete() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
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) -> ContextAwareInterface:
|
def __enter__(self) -> Incomplete:
|
||||||
super().__enter__()
|
super().__enter__() # type: ignore
|
||||||
|
return self
|
||||||
|
|
||||||
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
|
||||||
@@ -55,7 +57,7 @@ def test_exit_raises_not_implemented_if_not_overwritten() -> None:
|
|||||||
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:
|
||||||
super().__exit__(exc_type, exc_val, exc_tb)
|
super().__exit__(exc_type, exc_val, exc_tb) # type: ignore
|
||||||
|
|
||||||
instance = Incomplete()
|
instance = Incomplete()
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
|
|||||||
@@ -109,23 +109,6 @@ def test_connect_raises_connection_error_when_unable_to_ping(
|
|||||||
adapter.connect()
|
adapter.connect()
|
||||||
|
|
||||||
|
|
||||||
def test_should_connect_and_disconnect(
|
|
||||||
redis_container: str,
|
|
||||||
) -> None:
|
|
||||||
"""Test that the RedisAdapter can connect and disconnect."""
|
|
||||||
# Connect
|
|
||||||
adapter = RedisAdapter()
|
|
||||||
adapter.connect()
|
|
||||||
# Assert connected
|
|
||||||
assert adapter._client is not None
|
|
||||||
assert adapter.is_connected
|
|
||||||
# Disconnect
|
|
||||||
adapter.disconnect()
|
|
||||||
# Assert disconnected
|
|
||||||
assert adapter._client is None
|
|
||||||
assert not adapter.is_connected
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_log_error_on_exception_during_exit(
|
def test_should_log_error_on_exception_during_exit(
|
||||||
redis_container: str,
|
redis_container: str,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
@@ -183,7 +166,7 @@ def test_should_raise_value_error_on_invalid_get_key(
|
|||||||
# Act & Assert
|
# Act & Assert
|
||||||
for key in invalid_keys:
|
for key in invalid_keys:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
redis_adapter._get(key)
|
redis_adapter._get(key) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_connection_error_on_get_when_not_connected(
|
def test_should_raise_connection_error_on_get_when_not_connected(
|
||||||
@@ -234,7 +217,7 @@ def test_should_raise_value_error_on_invalid_set_key(
|
|||||||
# Act & Assert
|
# Act & Assert
|
||||||
for key in invalid_keys:
|
for key in invalid_keys:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
redis_adapter._set(key, data)
|
redis_adapter._set(key, data) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_value_error_on_invalid_set_data(
|
def test_should_raise_value_error_on_invalid_set_data(
|
||||||
@@ -247,7 +230,7 @@ def test_should_raise_value_error_on_invalid_set_data(
|
|||||||
# Act & Assert
|
# Act & Assert
|
||||||
for data in invalid_data:
|
for data in invalid_data:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
redis_adapter._set(key, data)
|
redis_adapter._set(key, data) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_connection_error_on_set_when_not_connected(
|
def test_should_raise_connection_error_on_set_when_not_connected(
|
||||||
@@ -285,7 +268,7 @@ def test_should_raise_value_error_on_invalid_delete_key(
|
|||||||
# Act & Assert
|
# Act & Assert
|
||||||
for key in invalid_keys:
|
for key in invalid_keys:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
redis_adapter._delete(key)
|
redis_adapter._delete(key) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_connection_error_on_delete_when_not_connected(
|
def test_should_raise_connection_error_on_delete_when_not_connected(
|
||||||
@@ -321,7 +304,7 @@ def test_should_raise_value_error_on_invalid_list_keys_pattern(
|
|||||||
# Act & Assert
|
# Act & Assert
|
||||||
for pattern in invalid_patterns:
|
for pattern in invalid_patterns:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
redis_adapter._list_keys(pattern)
|
redis_adapter._list_keys(pattern) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_should_raise_connection_error_on_list_keys_when_not_connected(
|
def test_should_raise_connection_error_on_list_keys_when_not_connected(
|
||||||
|
|||||||
Reference in New Issue
Block a user