def test_factory_func_remove(function_factory: FunctionFactoryBase): assert not function_factory.funcs_user initial_funcs_n = len(function_factory.funcs_inst) const_cls = function_factory.get('ConstFunc') f = const_cls(function_factory=function_factory, duration=4, a=.7, name='f') function_factory.add_func(f) f2 = const_cls(function_factory=function_factory, duration=4, a=.7, name='f2') function_factory.add_func(f2) assert len(function_factory.funcs_inst) == initial_funcs_n + 2 function_factory.test_changes_count = 0 assert function_factory.remove_func(f2) assert function_factory.test_changes_count assert f in function_factory.funcs_user assert f2 not in function_factory.funcs_user assert len(function_factory.funcs_user) == 1 assert f.name == 'f' assert f2.name == 'f2' assert function_factory.funcs_inst['f'] is f assert 'f2' not in function_factory.funcs_inst assert len(function_factory.funcs_inst) == initial_funcs_n + 1 function_factory.test_changes_count = 0 f2.name = 'f' assert not function_factory.test_changes_count assert f.name == 'f' assert f2.name == 'f' function_factory.test_changes_count = 0 assert function_factory.remove_func(f) assert function_factory.test_changes_count assert f not in function_factory.funcs_user assert f2 not in function_factory.funcs_user assert not function_factory.funcs_user assert f.name == 'f' assert f2.name == 'f' assert 'f' not in function_factory.funcs_inst assert 'f2' not in function_factory.funcs_inst assert len(function_factory.funcs_inst) == initial_funcs_n
def test_remove_func_with_ref(function_factory: FunctionFactoryBase): const_cls = function_factory.get('ConstFunc') f = const_cls(function_factory=function_factory, duration=4, a=.7, name='f') f2 = const_cls(function_factory=function_factory, duration=5, a=.9, name='f2') f3 = const_cls(function_factory=function_factory, duration=5, a=.9, name='f3') function_factory.add_func(f) function_factory.add_func(f2) function_factory.add_func(f3) assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user assert function_factory.funcs_inst['f2'] is f2 assert f2 in function_factory.funcs_user assert function_factory.funcs_inst['f3'] is f3 assert f3 in function_factory.funcs_user ref = function_factory.get_func_ref(name='f') ref3 = function_factory.get_func_ref(name='f3') assert not function_factory.remove_func(f) assert ref.func is f assert f.has_ref assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user assert function_factory.funcs_inst['f2'] is f2 assert f2 in function_factory.funcs_user assert function_factory.funcs_inst['f3'] is f3 assert f3 in function_factory.funcs_user assert function_factory.remove_func(f2) assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user assert 'f2' not in function_factory.funcs_inst assert f2 not in function_factory.funcs_user assert function_factory.funcs_inst['f3'] is f3 assert f3 in function_factory.funcs_user assert not function_factory.remove_func(f3) assert ref3.func is f3 assert f3.has_ref assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user assert function_factory.funcs_inst['f3'] is f3 assert f3 in function_factory.funcs_user assert function_factory.remove_func(f3, force=True) assert ref3.func is f3 assert f3.has_ref assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user assert 'f3' not in function_factory.funcs_inst assert f3 not in function_factory.funcs_user assert not function_factory.remove_func(f) assert ref.func is f assert f.has_ref assert function_factory.funcs_inst['f'] is f assert f in function_factory.funcs_user function_factory.return_func_ref(ref) assert not f.has_ref assert function_factory.remove_func(f) assert 'f' not in function_factory.funcs_inst assert f not in function_factory.funcs_user function_factory.return_func_ref(ref3) assert not f3.has_ref