mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 16:50:02 +02:00
Merge pull request #26 from tiqi-group/24-issue-pydase-checks-if-protected-variables-inherit-from-dataservice
fix: only check inheritance of public attributes
This commit is contained in:
commit
e3a7932ac4
@ -83,8 +83,9 @@ class DataService(rpyc.Service, AbstractDataService):
|
|||||||
|
|
||||||
def __check_instance_classes(self) -> None:
|
def __check_instance_classes(self) -> None:
|
||||||
for attr_name, attr_value in get_class_and_instance_attributes(self).items():
|
for attr_name, attr_value in get_class_and_instance_attributes(self).items():
|
||||||
# every class defined by the user should inherit from DataService
|
# every class defined by the user should inherit from DataService if it is
|
||||||
if not attr_name.startswith("_DataService__"):
|
# assigned to a public attribute
|
||||||
|
if not attr_name.startswith("_"):
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService(attr_value)
|
warn_if_instance_class_does_not_inherit_from_DataService(attr_value)
|
||||||
|
|
||||||
def __set_attribute_based_on_type( # noqa:CFQ002
|
def __set_attribute_based_on_type( # noqa:CFQ002
|
||||||
|
@ -2,7 +2,7 @@ from pytest import LogCaptureFixture
|
|||||||
|
|
||||||
from pydase import DataService
|
from pydase import DataService
|
||||||
|
|
||||||
from . import caplog # noqa
|
from .. import caplog # noqa
|
||||||
|
|
||||||
|
|
||||||
def test_setattr_warnings(caplog: LogCaptureFixture) -> None: # noqa
|
def test_setattr_warnings(caplog: LogCaptureFixture) -> None: # noqa
|
||||||
@ -32,3 +32,19 @@ def test_private_attribute_warning(caplog: LogCaptureFixture) -> None: # noqa
|
|||||||
" Warning: You should not set private but rather protected attributes! Use "
|
" Warning: You should not set private but rather protected attributes! Use "
|
||||||
"_something instead of __something." in caplog.text
|
"_something instead of __something." in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_protected_attribute_warning(caplog: LogCaptureFixture) -> None: # noqa
|
||||||
|
class SubClass:
|
||||||
|
name = "Hello"
|
||||||
|
|
||||||
|
class ServiceClass(DataService):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self._subclass = SubClass
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
ServiceClass()
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Warning: Class SubClass does not inherit from DataService." not in caplog.text
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user