mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-11 07:47:12 +02:00
Merge branch 'main' into feature/ignore_coroutine
This commit is contained in:
@ -36,7 +36,8 @@ def test_unexpected_type_change_warning(caplog: LogCaptureFixture) -> None:
|
||||
|
||||
|
||||
def test_basic_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
||||
class SubService(DataService): ...
|
||||
class SubService(DataService):
|
||||
...
|
||||
|
||||
class SomeEnum(Enum):
|
||||
HI = 0
|
||||
@ -56,9 +57,11 @@ def test_basic_inheritance_warning(caplog: LogCaptureFixture) -> None:
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
def some_method(self) -> None: ...
|
||||
def some_method(self) -> None:
|
||||
...
|
||||
|
||||
async def some_task(self) -> None: ...
|
||||
async def some_task(self) -> None:
|
||||
...
|
||||
|
||||
ServiceClass()
|
||||
|
||||
|
@ -138,7 +138,6 @@ def test_removed_observer_on_class_dict_attr(caplog: pytest.LogCaptureFixture) -
|
||||
caplog.clear()
|
||||
|
||||
assert nested_instance._observers == {
|
||||
'["nested"]': [],
|
||||
"nested_attr": [instance],
|
||||
}
|
||||
|
||||
@ -172,7 +171,6 @@ def test_removed_observer_on_instance_dict_attr(
|
||||
caplog.clear()
|
||||
|
||||
assert nested_instance._observers == {
|
||||
'["nested"]': [],
|
||||
"nested_attr": [instance],
|
||||
}
|
||||
|
||||
@ -211,6 +209,6 @@ def test_pop(caplog: pytest.LogCaptureFixture) -> None:
|
||||
instance = MyObservable()
|
||||
MyObserver(instance)
|
||||
assert instance.dict_attr.pop("nested") == nested_instance
|
||||
assert nested_instance._observers == {'["nested"]': []}
|
||||
assert nested_instance._observers == {}
|
||||
|
||||
assert f"'dict_attr' changed to '{instance.dict_attr}'" in caplog.text
|
||||
|
@ -81,11 +81,21 @@ def test_removed_observer_on_class_list_attr(caplog: pytest.LogCaptureFixture) -
|
||||
|
||||
instance = MyObservable()
|
||||
MyObserver(instance)
|
||||
|
||||
assert nested_instance._observers == {
|
||||
"[0]": [instance.changed_list_attr],
|
||||
"nested_attr": [instance],
|
||||
}
|
||||
|
||||
instance.changed_list_attr[0] = "Ciao"
|
||||
|
||||
assert "'changed_list_attr[0]' changed to 'Ciao'" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
assert nested_instance._observers == {
|
||||
"nested_attr": [instance],
|
||||
}
|
||||
|
||||
instance.nested_attr.name = "Hi"
|
||||
|
||||
assert "'nested_attr.name' changed to 'Hi'" in caplog.text
|
||||
@ -115,6 +125,10 @@ def test_removed_observer_on_instance_list_attr(
|
||||
assert "'changed_list_attr[0]' changed to 'Ciao'" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
assert nested_instance._observers == {
|
||||
"nested_attr": [instance],
|
||||
}
|
||||
|
||||
instance.nested_attr.name = "Hi"
|
||||
|
||||
assert "'nested_attr.name' changed to 'Hi'" in caplog.text
|
||||
@ -311,3 +325,51 @@ def test_list_remove(caplog: pytest.LogCaptureFixture) -> None:
|
||||
# checks if observer key was updated correctly (was index 1)
|
||||
other_observable_instance_2.greeting = "Ciao"
|
||||
assert "'my_list[0].greeting' changed to 'Ciao'" in caplog.text
|
||||
|
||||
|
||||
def test_list_garbage_collection() -> None:
|
||||
"""Makes sure that the GC collects lists that are not referenced anymore."""
|
||||
|
||||
import gc
|
||||
import json
|
||||
|
||||
list_json = """
|
||||
[1]
|
||||
"""
|
||||
|
||||
class MyObservable(Observable):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.list_attr = json.loads(list_json)
|
||||
|
||||
observable = MyObservable()
|
||||
list_mapping_length = len(observable._list_mapping)
|
||||
observable.list_attr = json.loads(list_json)
|
||||
|
||||
gc.collect()
|
||||
assert len(observable._list_mapping) <= list_mapping_length
|
||||
|
||||
|
||||
def test_dict_garbage_collection() -> None:
|
||||
"""Makes sure that the GC collects dicts that are not referenced anymore."""
|
||||
|
||||
import gc
|
||||
import json
|
||||
|
||||
dict_json = """
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
"""
|
||||
|
||||
class MyObservable(Observable):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.dict_attr = json.loads(dict_json)
|
||||
|
||||
observable = MyObservable()
|
||||
dict_mapping_length = len(observable._dict_mapping)
|
||||
observable.dict_attr = json.loads(dict_json)
|
||||
|
||||
gc.collect()
|
||||
assert len(observable._dict_mapping) <= dict_mapping_length
|
||||
|
@ -16,6 +16,7 @@ def test_inherited_property_dependency_resolution() -> None:
|
||||
_name = "DerivedObservable"
|
||||
|
||||
class MyObserver(PropertyObserver):
|
||||
def on_change(self, full_access_path: str, value: Any) -> None: ...
|
||||
def on_change(self, full_access_path: str, value: Any) -> None:
|
||||
...
|
||||
|
||||
assert MyObserver(DerivedObservable()).property_deps_dict == {"_name": ["name"]}
|
||||
|
@ -476,7 +476,8 @@ def test_derived_data_service_serialization() -> None:
|
||||
def name(self, value: str) -> None:
|
||||
self._name = value
|
||||
|
||||
class DerivedService(BaseService): ...
|
||||
class DerivedService(BaseService):
|
||||
...
|
||||
|
||||
base_service_serialization = dump(BaseService())
|
||||
derived_service_serialization = dump(DerivedService())
|
||||
|
Reference in New Issue
Block a user