def test_multple(self): hook_manager = HookManager() hook_manager.add_hook("test", lambda: 43) hook_manager.add_hook("test", lambda: 42) hook_manager.add_hook("test", lambda: 44) retval = hook_manager.call_hook("test") assert set(retval) == {42, 43, 44}
def test_exception(self): """ Hook Manager should silently ignore hooks that make exceptions""" hook_manager = HookManager() hook_manager.add_hook("test", self.make_exception) hook_manager.add_hook("test", lambda: 42) retval = hook_manager.call_hook("test") assert retval == [42]
def test_no_problems(self): try: inginious.common.tasks.Task( self.course_factory.get_course('test3'), 'invalid_task', {"environment": "default"}, 'fake_path', HookManager()) except Exception as e: assert str(e) == "Tasks must have some problems descriptions" return assert False
def test_invalid_limits_1(self): try: t = inginious.common.tasks.Task(self.course_factory.get_course('test3'), 'invalid_task', {"environment": "default", "limits": {"time": "a string!"}}, 'fake_path', None, HookManager(), problem_types) a = t.get_limits() print(a) except Exception as e: assert str(e) == "Invalid limit" return assert False
def test_invalid_limits_2(self): try: inginious.common.tasks.Task( self.course_factory.get_course('test3'), 'invalid_task', { "environment": "default", "limits": { "time": -1 } }, 'fake_path', HookManager()) except Exception as e: assert str(e) == "Invalid limit" return assert False
def create_factories(task_directory, hook_manager=None, course_class=Course, task_class=Task): """ Shorthand for creating Factories :param task_directory: :param hook_manager: an Hook Manager instance. If None, a new Hook Manager is created :param course_class: :param task_class: :return: a tuple with two objects: the first being of type CourseFactory, the second of type TaskFactory """ if hook_manager is None: hook_manager = HookManager() task_factory = TaskFactory(task_directory, hook_manager, task_class) return CourseFactory(task_directory, task_factory, hook_manager, course_class), task_factory
def test_no_problems(self): try: inginious.common.tasks.Task( self.course_factory.get_course('test3'), 'invalid_task', { "environment_id": "default", "environment_type": "docker", "environment_parameters": { "run_cmd": '', "limits": '0', "time": '30', "memory": '100', "hard_time": '', } }, 'fake_path', None, HookManager(), problem_types) except Exception as e: assert str(e) == "Tasks must have some problems descriptions" return assert False
def create_factories(fs_provider, task_problem_types, hook_manager=None, course_class=Course, task_class=Task): """ Shorthand for creating Factories :param fs_provider: A FileSystemProvider leading to the courses :param hook_manager: an Hook Manager instance. If None, a new Hook Manager is created :param course_class: :param task_class: :return: a tuple with two objects: the first being of type CourseFactory, the second of type TaskFactory """ if hook_manager is None: hook_manager = HookManager() task_factory = TaskFactory(fs_provider, hook_manager, task_problem_types, task_class) return CourseFactory(fs_provider, task_factory, hook_manager, course_class), task_factory
def __init__(self, image_aliases, hook_manager=None, is_testing=False): """ Creates a job manager. :param image_aliases: a dict of image aliases, like {"default": "ingi/inginious-c-default"}. :param hook_manager: An instance of HookManager. If no instance is given(None), a new one will be created. """ self._closed = False self._is_testing = is_testing self._image_aliases = image_aliases self._hook_manager = HookManager( ) if hook_manager is None else hook_manager self._running_job_data = {} self._running_batch_job_data = {} self._batch_container_args = {} self._active_ssh_debug_servers = {} self._logger = logging.getLogger("inginious.backend") self._logger.info("Job Manager initialization done") self._hook_manager.call_hook("job_manager_init_done", job_manager=self)
def create_factories(fs_provider, task_problem_types, template_repo, hook_manager=None, course_class=Template, task_class=Task): """ [Source code integration]: make function genral for course and template Shorthand for creating Factories :param fs_provider: A FileSystemProvider leading to the courses :param template_repo: the repository containing the list of git templates :param hook_manager: an Hook Manager instance. If None, a new Hook Manager is created :param course_class: :param task_class: :return: a tuple with two objects: the first being of type CourseFactory, the second of type TaskFactory """ if hook_manager is None: hook_manager = HookManager() task_factory = TaskFactory(fs_provider, hook_manager, task_problem_types, task_class) return TemplateFactory(fs_provider, task_factory, template_repo, hook_manager, course_class), task_factory
def generate_hook_manager(self): hook_manager = HookManager() hook_manager.add_hook("new_job", self._hook) return hook_manager