def test_reciproc(self): """Test the reciprocity of path and lookup functions. """ _path = 'canopsis.common.utils.path' # path(lookup(elt)) == elt self.assertEqual(path(lookup(_path)), _path) # lookup(path(path)) == path self.assertEqual(lookup(path(path)), path)
def register_task(_id=None, force=False): """ Decorator which registers function in registered tasks with function _id """ if isroutine(_id): # if _id is a routine <=> no parameter is given # _id is routine _id result = _id # task is the routine _id = path(_id) # task id is its python path register_tasks(force=force, **{_id: result}) else: # if _id is a str or None def register_task(function, _id=_id): """ Register input function as a task """ if _id is None: _id = path(function) register_tasks(force=force, **{_id: function}) return function result = register_task return result
def test_with_routine(self): """ Test to generate a new conf related to a task routine. """ conf = new_conf(run_task) self.assertEqual(conf['id'], path(run_task))
def test_get_unregisteredtask(self): """ Test to get unregistered task. """ getTaskTest = path(GetTaskTest) task = get_task(getTaskTest) self.assertEqual(task, GetTaskTest)
def __init__(self, name, bases, attrs): super(MetaConfigurationDriver, self).__init__(name, bases, attrs) # if the class claims to be registered if self.__register__: # add it among drivers ConfigurationDriver._MANAGERS[path(self)] = self
def test_raise(self): def toto(): pass _id = path(toto) register_tasks(force=True, **{_id: 6}) self.assertRaises(TaskError, register_task, toto)
def test_path(self): """Test the path function. """ # resolve built-in function open_path = path(open) self.assertEqual(open_path, '__builtin__.open') # resolve path self.assertEqual(path(path), 'canopsis.common.utils.path') # resolve package import canopsis self.assertEqual(path(canopsis), 'canopsis') # resolve sub-module import canopsis.common as canopsis_common self.assertEqual(path(canopsis_common), 'canopsis.common')
def test_with_routine_and_params(self): """ Test to generate a new conf related to a task routine and params. """ params = {'a': 1} conf = new_conf(run_task, **params) self.assertEqual(conf[TASK_ID], path(run_task)) self.assertEqual(conf[TASK_PARAMS], params)
def register_task(function, _id=_id): """ Register input function as a task """ if _id is None: _id = path(function) register_tasks(force=force, **{_id: function}) return function
def to_dict(self): """Transform self to a dict in storing public attributes. """ result = {} # set public attributes for slot in self.__slots__: if slot[0] != '_': result[slot] = getattr(self, slot) # set class type self_type = type(self) result[GraphElement._CLS] = path(self_type) # set base type result[GraphElement.BASE_TYPE] = self.BASE_TYPE return result
def test_register(self): @register_task(force=True) def register(): pass self.assertIn(path(register), TASKS_BY_ID)
def test_register_without_parameters(self): def register(): pass register_task(force=True)(register) self.assertIn(path(register), TASKS_BY_ID)