def test_function_existing_function_can_be_unsubscribed(self): FunctionFactory.subscribe(TestFunctionCorrectForm) nfuncs_before = len(FunctionFactory.getFunctionNames()) FunctionFactory.unsubscribe("TestFunctionCorrectForm") available_functions = FunctionFactory.getFunctionNames() self.assertEquals(nfuncs_before - 1, len(available_functions)) self.assertTrue("TestFunctionCorrectForm" not in available_functions)
def test_function_subscription(self): nfuncs_orig = len(FunctionFactory.getFunctionNames()) FunctionFactory.subscribe(TestFunction) new_funcs = FunctionFactory.getFunctionNames() self.assertEquals(nfuncs_orig+1, len(new_funcs)) self.assertTrue("TestFunction" in new_funcs) FunctionFactory.unsubscribe("TestFunction") new_funcs = FunctionFactory.getFunctionNames() self.assertEquals(nfuncs_orig, len(new_funcs)) self.assertTrue("TestFunction" not in new_funcs)
def test_category_override_returns_overridden_result(self): FunctionFactory.subscribe(Times2) func = FunctionFactory.createFunction("Times2") self.assertEquals("SimpleFunction", func.category()) FunctionFactory.unsubscribe("Times2")
def test_category_with_no_override_returns_default_category(self): FunctionFactory.subscribe(NoCatgeoryFunction) func = FunctionFactory.createFunction("NoCatgeoryFunction") self.assertEquals("General", func.category()) FunctionFactory.unsubscribe("NoCatgeoryFunction")
def test_instance_can_be_created_from_factory(self): FunctionFactory.subscribe(Times2) func_name = Times2.__name__ func = FunctionFactory.createFunction(func_name) self.assertTrue(isinstance(func, IFunction1D)) FunctionFactory.unsubscribe(func_name)