mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
updates tests for is_property_attribute
This commit is contained in:
parent
f315cd62d6
commit
1ee6a299b2
@ -170,7 +170,9 @@ def get_data_service_class_reference() -> Any:
|
|||||||
def is_property_attribute(target_obj: Any, access_path: str) -> bool:
|
def is_property_attribute(target_obj: Any, access_path: str) -> bool:
|
||||||
path_parts = parse_full_access_path(access_path)
|
path_parts = parse_full_access_path(access_path)
|
||||||
target_obj = get_object_by_path_parts(target_obj, path_parts[:-1])
|
target_obj = get_object_by_path_parts(target_obj, path_parts[:-1])
|
||||||
# TODO: check if target_obj is dict or list
|
|
||||||
|
# don't have to check if target_obj is dict or list as their content cannot be
|
||||||
|
# properties -> always return False then
|
||||||
return isinstance(getattr(type(target_obj), path_parts[-1], None), property)
|
return isinstance(getattr(type(target_obj), path_parts[-1], None), property)
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,13 +108,29 @@ def test_get_object_by_path_parts(path_parts: list[str], expected: Any) -> None:
|
|||||||
("my_property", True),
|
("my_property", True),
|
||||||
("my_method", False),
|
("my_method", False),
|
||||||
("non_existent_attr", False),
|
("non_existent_attr", False),
|
||||||
|
("nested_class_instance", False),
|
||||||
|
("nested_class_instance.my_property", True),
|
||||||
|
("list_attr", False),
|
||||||
|
("list_attr[0]", False),
|
||||||
|
("list_attr[0].my_property", True),
|
||||||
|
("dict_attr", False),
|
||||||
|
("dict_attr['foo']", False),
|
||||||
|
("dict_attr['foo'].my_property", True),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_is_property_attribute(attr_name: str, expected: bool) -> None:
|
def test_is_property_attribute(attr_name: str, expected: bool) -> None:
|
||||||
|
class NestedClass:
|
||||||
|
@property
|
||||||
|
def my_property(self) -> str:
|
||||||
|
return "I'm a nested property"
|
||||||
|
|
||||||
# Test Suite
|
# Test Suite
|
||||||
class DummyClass:
|
class DummyClass:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.regular_attribute = "I'm just an attribute"
|
self.regular_attribute = "I'm just an attribute"
|
||||||
|
self.nested_class_instance = NestedClass()
|
||||||
|
self.list_attr = [NestedClass()]
|
||||||
|
self.dict_attr = {"foo": NestedClass()}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def my_property(self) -> str:
|
def my_property(self) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user