def execute(name: str, raw_args: str, response: Response = None, remote_connection: 'environ.RemoteConnection' = None) -> Response: """ :return: """ if not response: response = Response(identifier=name) command_module = fetch().get(name) if command_module is None: return response.fail( code='NO_SUCH_COMMAND', message='There is no command "{}"'.format(name)).kernel( name=name).console(""" "{name}" is not a recognized command. For a list of available commands enter help or ?. """.format(name=name)).response args = parse.args(command_module, raw_args) response.consume(args.response) if args.parser is None: # The parse failed and the execution should be aborted return response if args.args is None or args.args['show_help']: # Overrides standard execution and instead displays the help for the # command args.parser.print_help() return response del args.args['show_help'] context = cli.make_command_context(name=name, args=args.args, raw_args=raw_args, parser=args.parser, response=response, remote_connection=remote_connection) response.update(remote_connection=remote_connection) if not context.remote_connection.active and name == 'run': preload() t = CauldronThread() t.command = get_command_from_module( command_module=command_module, remote_connection=context.remote_connection) t.context = context t.parser = args.parser t.kwargs = args.args t.response = response response.thread = t t.start() return response
def activate_execution( self, uid: str, is_alive: bool = True ) -> Response: """ Adds a fake running command execution to the run status list for use in testing """ r = Response(identifier=uid) def is_thread_alive(): return is_alive r.thread = MagicMock() r.thread.uid = uid r.thread.is_alive = is_thread_alive r.thread.is_running = is_alive r.thread.logs = [] self.deactivate_execution(uid) self.active_responses[uid] = r server_runner.active_execution_responses[uid] = r return r
def activate_execution(self, uid: str, is_alive: bool = True) -> Response: """ Adds a fake running command execution to the run status list for use in testing """ r = Response(identifier=uid) def is_thread_alive(): return is_alive r.thread = FakeThread(is_alive=is_thread_alive, uid=uid) self.deactivate_execution(uid) self.active_responses[uid] = r server_runner.active_execution_responses[uid] = r return r
def execute_replacement(name, args, response: Response): response.thread = thread
def test_join_thread(self): """Should join the associated thread and return True""" r = Response() r.thread = MagicMock() self.assertTrue(r.join()) self.assertEqual(1, r.thread.join.call_count)