"""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)