mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-22 09:10:01 +02:00
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
from pydase import DataService
|
|
from pytest import LogCaptureFixture
|
|
|
|
|
|
def test_class_attr_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
|
class SubClass:
|
|
name = "Hello"
|
|
|
|
class ServiceClass(DataService):
|
|
attr_1 = SubClass()
|
|
|
|
ServiceClass()
|
|
|
|
assert (
|
|
"Class 'SubClass' does not inherit from DataService. This may lead to "
|
|
"unexpected behaviour!"
|
|
) in caplog.text
|
|
|
|
|
|
def test_instance_attr_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
|
class SubClass:
|
|
name = "Hello"
|
|
|
|
class ServiceClass(DataService):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self.attr_1 = SubClass()
|
|
|
|
ServiceClass()
|
|
|
|
assert (
|
|
"Class 'SubClass' does not inherit from DataService. This may lead to "
|
|
"unexpected behaviour!"
|
|
) in caplog.text
|
|
|
|
|
|
def test_private_attribute_warning(caplog: LogCaptureFixture) -> None:
|
|
class ServiceClass(DataService):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self.__something = ""
|
|
|
|
ServiceClass()
|
|
|
|
assert (
|
|
" Warning: You should not set private but rather protected attributes! Use "
|
|
"_something instead of __something." in caplog.text
|
|
)
|
|
|
|
|
|
def test_protected_attribute_warning(caplog: LogCaptureFixture) -> None:
|
|
class SubClass:
|
|
name = "Hello"
|
|
|
|
class ServiceClass(DataService):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self._subclass = SubClass
|
|
|
|
ServiceClass()
|
|
|
|
assert (
|
|
"Warning: Class SubClass does not inherit from DataService." not in caplog.text
|
|
)
|