def execute(task_name: str, abort: bool = False, options: Union[dict, argparse.Namespace] = None) -> Task: """ Use to execute one test task from config. :param task_name: Name of task to execute. :param abort: If `True` expect (and require) this task to abort. :param options: Options for the execution. """ logger.info('********** Running task: {} ********** ', task_name) config = manager.config['tasks'][task_name] task = Task(manager, task_name, config=config, options=options) try: if abort: with pytest.raises(TaskAbort): task.execute() else: task.execute() finally: try: task.session.close() except Exception: pass return task
def on_task_input(self, task, config): target_task_name = config subtask_name = '{}>{}'.format(task.name, target_task_name) subtask_config = task.manager.config['tasks'].get(target_task_name, {}) # TODO: This seen disabling is sorta hacky, is there a better way? subtask_config.setdefault('seen', False) input_task = Task( task.manager, subtask_name, config=subtask_config, # TODO: Do we want to pass other options through? # TODO: Manual plugin semantics and allow_manual are confusing. Make it less confusing somehow? options={ 'allow_manual': True, 'tasks': [subtask_name] }, output=task.output, session_id=task.session_id, priority=task.priority, ) logger.verbose('Running task `{}` as subtask.', target_task_name) input_task.execute() logger.verbose('Finished running subtask `{}`.', target_task_name) # Create fresh entries to reset state and strip association to old task return [Entry(e) for e in input_task.accepted]
def execute(task_name, abort=False, options=None): """ Use to execute one test task from config. :param abort: If `True` expect (and require) this task to abort. """ log.info('********** Running task: %s ********** ' % task_name) config = manager.config['tasks'][task_name] task = Task(manager, task_name, config=config, options=options) try: if abort: with pytest.raises(TaskAbort): task.execute() else: task.execute() finally: try: task.session.close() except Exception: pass return task
class FlexGetBase(object): __yaml__ = """# Yaml goes here""" # Set this to True to get a UNIQUE tmpdir; the tmpdir is created on # setup as "./tmp/<testname>" and automatically removed on teardown. # # The instance variable __tmp__ is set to the absolute name of the tmpdir # (ending with "os.sep"), and any occurrence of "__tmp__" in __yaml__ or # a @with_filecopy destination is also replaced with it. __tmp__ = False def __init__(self): self.log = log self.manager = None self.task = None self.database_uri = None self.base_path = os.path.dirname(__file__) def setup(self): """Set up test env""" setup_once() if self.__tmp__: self.__tmp__ = util.maketemp() + '/' self.__yaml__ = self.__yaml__.replace("__tmp__", self.__tmp__) self.manager = MockManager(self.__yaml__, self.__class__.__name__, db_uri=self.database_uri) def teardown(self): try: try: self.task.session.close() except: pass self.manager.shutdown() self.manager.__del__() finally: if self.__tmp__: import shutil log.trace('Removing tmpdir %r' % self.__tmp__) shutil.rmtree(self.__tmp__.rstrip(os.sep)) def execute_task(self, name, abort_ok=False, options=None): """Use to execute one test task from config""" log.info('********** Running task: %s ********** ' % name) config = self.manager.config['tasks'][name] if hasattr(self, 'task'): if hasattr(self, 'session'): self.task.session.close() # pylint: disable-msg=E0203 self.task = Task(self.manager, name, config=config, options=options) try: self.task.execute() except TaskAbort: if not abort_ok: raise def dump(self): """Helper method for debugging""" from flexget.plugins.output.dump import dump #from flexget.utils.tools import sanitize # entries = sanitize(self.task.entries) # accepted = sanitize(self.task.accepted) # rejected = sanitize(self.task.rejected) print '\n-- ENTRIES: -----------------------------------------------------' # print yaml.safe_dump(entries) dump(self.task.entries, True) print '-- ACCEPTED: ----------------------------------------------------' # print yaml.safe_dump(accepted) dump(self.task.entries, True) print '-- REJECTED: ----------------------------------------------------' # print yaml.safe_dump(rejected) dump(self.task.entries, True)
class FlexGetBase(object): __yaml__ = """# Yaml goes here""" # Set this to True to get a UNIQUE tmpdir; the tmpdir is created on # setup as "./tmp/<testname>" and automatically removed on teardown. # # The instance variable __tmp__ is set to the absolute name of the tmpdir # (ending with "os.sep"), and any occurrence of "__tmp__" in __yaml__ or # a @with_filecopy destination is also replaced with it. __tmp__ = False def __init__(self): self.log = log self.manager = None self.task = None self.database_uri = None self.base_path = os.path.dirname(__file__) self.config_functions = [] self.tasks_functions = [] def add_config_function(self, config_function): self.config_functions.append(config_function) def add_tasks_function(self, tasks_function): self.tasks_functions.append(tasks_function) def setup(self): """Set up test env""" setup_once() if self.__tmp__: self.__tmp__ = util.maketemp() + '/' self.__yaml__ = self.__yaml__.replace("__tmp__", self.__tmp__) self.manager = MockManager(self.__yaml__, self.__class__.__name__, db_uri=self.database_uri) for config_function in self.config_functions: config_function(self.manager.config) if self.tasks_functions and 'tasks' in self.manager.config: for task_name, task_definition in self.manager.config[ 'tasks'].items(): for task_function in self.tasks_functions: task_function(task_name, task_definition) def teardown(self): try: try: self.task.session.close() except: pass self.manager.shutdown() self.manager.__del__() finally: if self.__tmp__: import shutil log.trace('Removing tmpdir %r' % self.__tmp__) shutil.rmtree(self.__tmp__.rstrip(os.sep)) def execute_task(self, name, abort_ok=False, options=None): """Use to execute one test task from config""" log.info('********** Running task: %s ********** ' % name) config = self.manager.config['tasks'][name] if hasattr(self, 'task'): if hasattr(self, 'session'): self.task.session.close() # pylint: disable-msg=E0203 self.task = Task(self.manager, name, config=config, options=options) try: self.task.execute() except TaskAbort: if not abort_ok: raise def dump(self): """Helper method for debugging""" from flexget.plugins.output.dump import dump #from flexget.utils.tools import sanitize # entries = sanitize(self.task.entries) # accepted = sanitize(self.task.accepted) # rejected = sanitize(self.task.rejected) print '\n-- ENTRIES: -----------------------------------------------------' # print yaml.safe_dump(entries) dump(self.task.entries, True) print '-- ACCEPTED: ----------------------------------------------------' # print yaml.safe_dump(accepted) dump(self.task.entries, True) print '-- REJECTED: ----------------------------------------------------' # print yaml.safe_dump(rejected) dump(self.task.entries, True)