added integration tests
Code Quality Pipeline / code-quality (pull_request) Failing after 43s
Test Python Package / test (pull_request) Failing after 11s

This commit is contained in:
Brian Bjarke Jensen
2025-09-14 19:52:47 +02:00
parent 524bd0f06b
commit 0948799653
4 changed files with 590 additions and 0 deletions
@@ -0,0 +1,62 @@
"""Integration tests for ContextAwareInterface."""
import pytest
from python_repositories.interfaces.context_aware_interface import ContextAwareInterface
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:
pass
with pytest.raises(TypeError):
_ = Incomplete()
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) -> ContextAwareInterface:
return self
with pytest.raises(TypeError):
_ = Incomplete()
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) -> ContextAwareInterface:
super().__enter__()
def __exit__(
self, exc_type: type | None, exc_val: object | None, exc_tb: object | None
) -> None:
pass
instance = Incomplete()
with pytest.raises(NotImplementedError):
instance.__enter__()
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
def __exit__(
self, exc_type: type | None, exc_val: object | None, exc_tb: object | None
) -> None:
super().__exit__(exc_type, exc_val, exc_tb)
instance = Incomplete()
with pytest.raises(NotImplementedError):
instance.__exit__(None, None, None)