def test_factory_re_register(function_factory: FunctionFactoryBase): from ceed.function.plugin import ConstFunc, LinearFunc with pytest.raises(Exception): function_factory.register(ConstFunc) with pytest.raises(Exception): function_factory.register(LinearFunc)
def test_register_funcs(): from ceed.function.plugin import ConstFunc, LinearFunc function_factory = FunctionFactoryBase() count = 0 def count_changes(*largs): nonlocal count count += 1 function_factory.fbind('on_changed', count_changes) assert not function_factory.funcs_cls assert not function_factory.funcs_user assert not function_factory.funcs_inst assert not function_factory.funcs_inst_default assert not function_factory.get_classes() assert not function_factory.get_names() function_factory.register(ConstFunc) assert count assert function_factory.funcs_cls['ConstFunc'] is ConstFunc assert isinstance(function_factory.funcs_inst['Const'], ConstFunc) assert isinstance(function_factory.funcs_inst_default['Const'], ConstFunc) assert ConstFunc in function_factory.get_classes() assert 'ConstFunc' in function_factory.get_names() f = LinearFunc(function_factory=function_factory) count = 0 function_factory.register(LinearFunc, instance=f) assert count assert function_factory.funcs_cls['LinearFunc'] is LinearFunc assert function_factory.funcs_inst['Linear'] is f assert function_factory.funcs_inst_default['Linear'] is f assert LinearFunc in function_factory.get_classes() assert 'LinearFunc' in function_factory.get_names() assert not function_factory.funcs_user