Fixed memory leak for instances
This commit is contained in:
@@ -129,9 +129,9 @@ class TestBaseInstance:
|
||||
assert instance.get_id() is not None
|
||||
assert instance.get_id().startswith("mf-base_instance-")
|
||||
|
||||
def test_i_can_get_prefix_from_class_name(self):
|
||||
def test_i_can_get_prefix_from_class_name(self, session):
|
||||
"""Test that get_prefix() returns the correct snake_case prefix."""
|
||||
prefix = BaseInstance.get_prefix()
|
||||
prefix = BaseInstance(None, session).get_prefix()
|
||||
|
||||
assert prefix == "mf-base_instance"
|
||||
|
||||
@@ -182,7 +182,7 @@ class TestSingleInstance:
|
||||
instance = SingleInstance(parent=None, session=session)
|
||||
|
||||
assert instance.get_id() == "mf-single_instance"
|
||||
assert instance.get_id() == SingleInstance.get_prefix()
|
||||
assert instance.get_prefix() == "mf-single_instance"
|
||||
|
||||
|
||||
class TestSingleInstanceSubclass:
|
||||
@@ -249,6 +249,18 @@ class TestMultipleInstance:
|
||||
instance2 = MultipleInstance(parent=root_instance, session=session, _id=custom_id)
|
||||
|
||||
assert instance1 is instance2
|
||||
|
||||
def test_key_prefixed_by_underscore_uses_the_parent_id_as_prefix(self, root_instance):
|
||||
"""Test that key prefixed by underscore uses the parent id as prefix."""
|
||||
instance = MultipleInstance(parent=root_instance, _id="-test_id")
|
||||
|
||||
assert instance.get_id() == f"{root_instance.get_id()}-test_id"
|
||||
|
||||
def test_no_parent_id_as_prefix_if_parent_is_none(self, session, root_instance):
|
||||
"""Test that key prefixed by underscore does not use the parent id as prefix if parent is None."""
|
||||
instance = MultipleInstance(parent=None, session=session, _id="-test_id")
|
||||
|
||||
assert instance.get_id() == "-test_id"
|
||||
|
||||
|
||||
class TestMultipleInstanceSubclass:
|
||||
@@ -295,9 +307,9 @@ class TestMultipleInstanceSubclass:
|
||||
with pytest.raises(TypeError):
|
||||
MultipleInstance(parent=root_instance, _id=instance1.get_id())
|
||||
|
||||
def test_i_can_get_correct_prefix_for_multiple_subclass(self):
|
||||
def test_i_can_get_correct_prefix_for_multiple_subclass(self, root_instance):
|
||||
"""Test that subclass has correct auto-generated prefix."""
|
||||
prefix = SubMultipleInstance.get_prefix()
|
||||
prefix = SubMultipleInstance(root_instance).get_prefix()
|
||||
|
||||
assert prefix == "mf-sub_multiple_instance"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user