mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-04 04:40:39 +02:00
updates tests
This commit is contained in:
parent
0faf347376
commit
6d23151d32
@ -39,6 +39,9 @@ def test_warning(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
status = MyStatus.RUNNING
|
||||
|
||||
ServiceClass()
|
||||
|
||||
assert (
|
||||
"Warning: Class MyStatus does not inherit from DataService." not in caplog.text
|
||||
"Class 'MyStatus' does not inherit from DataService. This may lead to "
|
||||
"unexpected behaviour!" not in caplog.text
|
||||
)
|
||||
|
@ -1,3 +1,5 @@
|
||||
from enum import Enum
|
||||
|
||||
import pydase.units as u
|
||||
from pydase import DataService
|
||||
from pydase.data_service.data_service_observer import DataServiceObserver
|
||||
@ -27,3 +29,84 @@ def test_unexpected_type_change_warning(caplog: LogCaptureFixture) -> None:
|
||||
"Type of 'current' changed from 'Quantity' to 'int'. This may have unwanted "
|
||||
"side effects! Consider setting it to 'Quantity' directly." in caplog.text
|
||||
)
|
||||
|
||||
|
||||
def test_basic_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
||||
class SubService(DataService):
|
||||
...
|
||||
|
||||
class SomeEnum(Enum):
|
||||
HI = 0
|
||||
|
||||
class ServiceClass(DataService):
|
||||
sub_service = SubService()
|
||||
some_int = 1
|
||||
some_float = 1.0
|
||||
some_bool = True
|
||||
some_quantity = 1.0 * u.units.A
|
||||
some_string = "Hello"
|
||||
some_enum = SomeEnum.HI
|
||||
_name = "Service"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
def some_method(self) -> None:
|
||||
...
|
||||
|
||||
ServiceClass()
|
||||
|
||||
# neither of the attributes, methods or properties cause a warning log
|
||||
assert "WARNING" not in caplog.text
|
||||
|
||||
|
||||
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_protected_and_private_attribute_warning(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass:
|
||||
name = "Hello"
|
||||
|
||||
class ServiceClass(DataService):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._subclass = SubClass()
|
||||
self.__other_subclass = SubClass()
|
||||
|
||||
ServiceClass()
|
||||
|
||||
# Protected and private attributes are not checked
|
||||
assert (
|
||||
"Class 'SubClass' does not inherit from DataService. This may lead to "
|
||||
"unexpected behaviour!"
|
||||
) not in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user