mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-05 21:20:40 +02:00
fixes warnings tests
This commit is contained in:
parent
1e55a4d914
commit
75ee71cbf8
@ -70,6 +70,11 @@ class DataService(rpyc.Service, AbstractDataService):
|
|||||||
# Warn if setting private attributes
|
# Warn if setting private attributes
|
||||||
self._warn_on_private_attr_set(__name)
|
self._warn_on_private_attr_set(__name)
|
||||||
|
|
||||||
|
# every class defined by the user should inherit from DataService if it is
|
||||||
|
# assigned to a public attribute
|
||||||
|
if not __name.startswith("_"):
|
||||||
|
warn_if_instance_class_does_not_inherit_from_data_service(__value)
|
||||||
|
|
||||||
# Set the attribute
|
# Set the attribute
|
||||||
super().__setattr__(__name, __value)
|
super().__setattr__(__name, __value)
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ def warn_if_instance_class_does_not_inherit_from_data_service(__value: object) -
|
|||||||
and type(__value).__name__ not in ["CallbackManager", "TaskManager", "Quantity"]
|
and type(__value).__name__ not in ["CallbackManager", "TaskManager", "Quantity"]
|
||||||
):
|
):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Warning: Class '%s' does not inherit from DataService.",
|
"Class '%s' does not inherit from DataService. This may lead to unexpected "
|
||||||
|
"behaviour!",
|
||||||
type(__value).__name__,
|
type(__value).__name__,
|
||||||
)
|
)
|
||||||
|
@ -2,8 +2,22 @@ from pydase import DataService
|
|||||||
from pytest import LogCaptureFixture
|
from pytest import LogCaptureFixture
|
||||||
|
|
||||||
|
|
||||||
def test_setattr_warnings(caplog: LogCaptureFixture) -> None:
|
def test_class_attr_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
||||||
# def test_setattr_warnings(capsys: CaptureFixture) -> 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:
|
class SubClass:
|
||||||
name = "Hello"
|
name = "Hello"
|
||||||
|
|
||||||
@ -14,7 +28,10 @@ def test_setattr_warnings(caplog: LogCaptureFixture) -> None:
|
|||||||
|
|
||||||
ServiceClass()
|
ServiceClass()
|
||||||
|
|
||||||
assert "Warning: Class 'SubClass' does not inherit from DataService." in caplog.text
|
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:
|
def test_private_attribute_warning(caplog: LogCaptureFixture) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user