import subprocess def _runcmd(ctx, argv): p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate("") ctx['stdout'] = stdout ctx['stderr'] = stderr ctx['exit'] = p.returncode def run_echo_without_args(ctx): _runcmd(ctx, ['echo']) def run_echo_with_args(ctx, args=None): _runcmd(ctx, ['echo', args]) def exit_code_is(ctx, exit_code=None): assert_eq(ctx['exit'], int(exit_code)) def stdout_is_a_newline(ctx): assert_eq(ctx['stdout'], b'\n') def stdout_is_text(ctx, text=None): text += '\n' text = text.encode() assert_eq(ctx['stdout'], text) def stderr_is_empty(ctx): assert_eq(ctx['stderr'], b'')