106 lines
3.1 KiB
Python
106 lines
3.1 KiB
Python
"""Integration tests for ConnectionAwareInterface."""
|
|
|
|
import pytest
|
|
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
|
|
|
|
@property
|
|
def is_connected(self) -> bool:
|
|
return False
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete()
|
|
|
|
|
|
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
|
|
|
|
@property
|
|
def is_connected(self) -> bool:
|
|
return False
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete()
|
|
|
|
|
|
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
|
|
|
|
def disconnect(self) -> None:
|
|
pass
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete()
|
|
|
|
|
|
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()
|
|
|
|
def disconnect(self) -> None:
|
|
pass
|
|
|
|
@property
|
|
def is_connected(self) -> bool:
|
|
return False
|
|
|
|
instance = Incomplete()
|
|
with pytest.raises(NotImplementedError):
|
|
instance.connect()
|
|
|
|
|
|
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
|
|
|
|
def disconnect(self) -> None:
|
|
super().disconnect()
|
|
|
|
@property
|
|
def is_connected(self) -> bool:
|
|
return False
|
|
|
|
instance = Incomplete()
|
|
with pytest.raises(NotImplementedError):
|
|
instance.disconnect()
|
|
|
|
|
|
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
|
|
|
|
def disconnect(self) -> None:
|
|
pass
|
|
|
|
@property
|
|
def is_connected(self) -> bool:
|
|
return super().is_connected
|
|
|
|
instance = Incomplete()
|
|
with pytest.raises(NotImplementedError):
|
|
_ = instance.is_connected
|