def test_init_wrongs_params(self): """ Test init with wrongs params """ clazz = classloader.load('clu.common.base.Configurable') with self.assertRaisesRegexp(classloader.ClassLoaderException, "__init__()"): instance = classloader.init(clazz, { "onfig" : {"one":1}} )
def test_init(self): """ Test init with params """ clazz = classloader.load('clu.common.base.Configurable') instance = classloader.init(clazz, { "config" : {"one":1}} ) self.assertFalse(instance.config is None) self.assertTrue(instance.config.one == 1)
def test_load_class(self): """ Test loading a class """ clazz = classloader.load('clu.common.base.Configurable') from clu.common.base import Configurable self.assertTrue(clazz == Configurable)
def loadclasses(self): """ Load classes from config """ if self._loadedconfig is None: raise AgentConfiguratorException("Config not loaded") if not self._loadedconfig.has_key("agents"): raise AgentConfiguratorException("Could not find agents in json config") for agent in self._loadedconfig["agents"]: if not agent.has_key("classname"): raise AgentConfiguratorException("Could not find agent classname json config") if not agent.has_key("name"): raise AgentConfiguratorException("Could not find agent name in json config") try: classname = agent["classname"] clazz = classloader.load(classname) self.__clazzs__[agent["name"]] = clazz except Exception, ex: LOGGER.error("Error disconnecting telnet client") raise AgentConfiguratorException, AgentConfiguratorException(ex), sys.exc_info()[2] # keep stacktrace
def test_load_class_witouht_module(self): """ Test that a classname without a module raiase an exception """ with self.assertRaisesRegexp(classloader.ClassLoaderException, "No module name found"): classloader.load('int')
def test_load_class_empty_classname(self): """ Test that an empty classname raise an exception """ with self.assertRaisesRegexp(classloader.ClassLoaderException, "No class name found"): classloader.load('clu.')