mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
adds test for dict/list garbage collection
This commit is contained in:
parent
f9a5352efe
commit
6a894b6154
@ -311,3 +311,51 @@ def test_list_remove(caplog: pytest.LogCaptureFixture) -> None:
|
|||||||
# checks if observer key was updated correctly (was index 1)
|
# checks if observer key was updated correctly (was index 1)
|
||||||
other_observable_instance_2.greeting = "Ciao"
|
other_observable_instance_2.greeting = "Ciao"
|
||||||
assert "'my_list[0].greeting' changed to 'Ciao'" in caplog.text
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user