def alloc_pty(ctx, f, *args, **kwargs): pid, fd = pty.fork() if pid == pty.CHILD: tty = os.ttyname(0) sys.stdin = open(tty, 'r') sys.stdout = open(tty, 'w') sys.stderr = open(tty, 'w') # alternative way of doing ^ is to do: # kwargs["stdout"] = open(tty, 'w') # kwargs["stderr"] = open(tty, 'w') # kwargs["stdin"] = open(tty, 'r') # Create a new client for the child process to avoid concurrency issues client = get_client() f(client, *args, **kwargs) sys.exit(0) else: ctx.pty = fd util.set_pty_size( ctx.pty, (ctx.rows, ctx.cols) ) ctx.pid = pid util.wait(ctx.pty, timeout=5) time.sleep(1) # give the terminal some time to print prompt # util.exit_code can be called only once ctx.exit_code = util.exit_code(ctx.pid, timeout=5) if ctx.exit_code != 0: raise Exception("child process did not finish correctly")
def alloc_pty(ctx, f, *args, **kwargs): pid, fd = pty.fork() if pid == pty.CHILD: tty = os.ttyname(0) sys.stdin = open(tty, 'r') sys.stdout = open(tty, 'w') sys.stderr = open(tty, 'w') # alternative way of doing ^ is to do: # kwargs["stdout"] = open(tty, 'w') # kwargs["stderr"] = open(tty, 'w') # kwargs["stdin"] = open(tty, 'r') # Create a new client for the child process to avoid concurrency issues client = get_client() f(client, *args, **kwargs) sys.exit(0) else: ctx.pty = fd util.set_pty_size(ctx.pty, (ctx.rows, ctx.cols)) ctx.pid = pid util.wait(ctx.pty, timeout=5) time.sleep(1) # give the terminal some time to print prompt # util.exit_code can be called only once ctx.exit_code = util.exit_code(ctx.pid, timeout=5) if ctx.exit_code != 0: raise Exception("child process did not finish correctly")
def step_impl(ctx): if not hasattr(ctx, "exit_code"): ctx.exit_code = util.exit_code(ctx.pid, timeout=5) expect(ctx.exit_code).to(equal(0))
def step_impl(ctx): expect(util.exit_code(ctx.pid, timeout=5)).to(equal(0))