Beispiel #1
0
    def _test_soft_switchable_extension(self):
        with temp_cwd(self.id()) as tmpdir:
            args = [sys.executable]
            args.extend(args_from_interpreter_flags())
            args.extend(["setup.py", "build", "-b", tmpdir, "install_lib", "-d", tmpdir, "--no-compile"])
            try:
                output = subprocess.check_output(args, stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT, cwd=self.demo_dir)
            except subprocess.CalledProcessError as e:
                if e.stdout:
                    sys.stdout.buffer.write(e.stdout)
                if e.stderr:
                    sys.stderr.buffer.write(e.stderr)
                raise
            if self.verbose:
                sys.stdout.buffer.write(output)
            py = glob.glob("*.py")
            self.assertEqual(len(py), 1)
            py = py[0]

            args = [sys.executable]
            args.extend(args_from_interpreter_flags())
            args.extend([py, '-v'])
            try:
                output = subprocess.check_output(args, stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                if e.stdout:
                    sys.stdout.buffer.write(e.stdout)
                if e.stderr:
                    sys.stderr.buffer.write(e.stderr)
                raise
            if self.verbose:
                sys.stdout.buffer.write(output)
Beispiel #2
0
def run_test_in_subprocess(testname, ns):
    """Run the given test in a subprocess with --slaveargs.

    ns is the option Namespace parsed from command-line arguments. regrtest
    is invoked in a subprocess with the --slaveargs argument; when the
    subprocess exits, its return code, stdout and stderr are returned as a
    3-tuple.
    """
    from subprocess import Popen, PIPE
    base_cmd = ([sys.executable] + support.args_from_interpreter_flags() +
                ['-X', 'faulthandler', '-m', 'test.regrtest'])

    slaveargs = (
            (testname, ns.verbose, ns.quiet),
            dict(huntrleaks=ns.huntrleaks,
                 use_resources=ns.use_resources,
                 output_on_failure=ns.verbose3,
                 timeout=ns.timeout, failfast=ns.failfast,
                 match_tests=ns.match_tests))
    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    popen = Popen(base_cmd + ['--slaveargs', json.dumps(slaveargs)],
                  stdout=PIPE, stderr=PIPE,
                  universal_newlines=True,
                  close_fds=(os.name != 'nt'),
                  cwd=support.SAVEDCWD)
    stdout, stderr = popen.communicate()
    retcode = popen.wait()
    return retcode, stdout, stderr
Beispiel #3
0
def run_test_in_subprocess(testname: str, ns: Namespace) -> subprocess.Popen:
    ns_dict = vars(ns)
    worker_args = (ns_dict, testname)
    worker_args = json.dumps(worker_args)

    cmd = [
        sys.executable,
        *support.args_from_interpreter_flags(),
        '-u',  # Unbuffered stdout and stderr
        '-m',
        'test.regrtest',
        '--worker-args',
        worker_args
    ]

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    kw = {}
    if USE_PROCESS_GROUP:
        kw['start_new_session'] = True
    return subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            universal_newlines=True,
                            close_fds=(os.name != 'nt'),
                            cwd=os_helper.SAVEDCWD,
                            **kw)
Beispiel #4
0
def run_test_in_subprocess(testname, ns):
    """Run the given test in a subprocess with --slaveargs.

    ns is the option Namespace parsed from command-line arguments. regrtest
    is invoked in a subprocess with the --slaveargs argument; when the
    subprocess exits, its return code, stdout and stderr are returned as a
    3-tuple.
    """
    from subprocess import Popen, PIPE

    ns_dict = vars(ns)
    slaveargs = (ns_dict, testname)
    slaveargs = json.dumps(slaveargs)

    cmd = [sys.executable, *support.args_from_interpreter_flags(),
           '-X', 'faulthandler',
           '-m', 'test.regrtest',
           '--slaveargs', slaveargs]
    if ns.pgo:
        cmd += ['--pgo']

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    popen = Popen(cmd,
                  stdout=PIPE, stderr=PIPE,
                  universal_newlines=True,
                  close_fds=(os.name != 'nt'),
                  cwd=support.SAVEDCWD)
    with popen:
        stdout, stderr = popen.communicate()
        retcode = popen.wait()
    return retcode, stdout, stderr
Beispiel #5
0
def run_test_in_subprocess(testname, ns):
    """Run the given test in a subprocess with --slaveargs.

    ns is the option Namespace parsed from command-line arguments. regrtest
    is invoked in a subprocess with the --slaveargs argument; when the
    subprocess exits, its return code, stdout and stderr are returned as a
    3-tuple.
    """
    from subprocess import Popen, PIPE

    ns_dict = vars(ns)
    slaveargs = (ns_dict, testname)
    slaveargs = json.dumps(slaveargs)

    cmd = [
        sys.executable, *support.args_from_interpreter_flags(), '-X',
        'faulthandler', '-m', 'test.regrtest', '--slaveargs', slaveargs
    ]
    if ns.pgo:
        cmd += ['--pgo']

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    popen = Popen(cmd,
                  stdout=PIPE,
                  stderr=PIPE,
                  universal_newlines=True,
                  close_fds=(os.name != 'nt'),
                  cwd=support.SAVEDCWD)
    with popen:
        stdout, stderr = popen.communicate()
        retcode = popen.wait()
    return retcode, stdout, stderr
Beispiel #6
0
def run_test_in_subprocess(testname, ns):
    """Run the given test in a subprocess with --slaveargs.

    ns is the option Namespace parsed from command-line arguments. regrtest
    is invoked in a subprocess with the --slaveargs argument; when the
    subprocess exits, its return code, stdout and stderr are returned as a
    3-tuple.
    """
    from subprocess import Popen, PIPE
    ns_dict = vars(ns)
    slaveargs = ns_dict, testname
    slaveargs = json.dumps(slaveargs)
    cmd = [
        sys.executable, *support.args_from_interpreter_flags(), '-u', '-m',
        'test.regrtest', '--slaveargs', slaveargs
    ]
    if ns.pgo:
        cmd += ['--pgo']
    popen = Popen(cmd,
                  stdout=PIPE,
                  stderr=PIPE,
                  universal_newlines=True,
                  close_fds=os.name != 'nt',
                  cwd=support.SAVEDCWD)
    with popen:
        stdout, stderr = popen.communicate()
        retcode = popen.wait()
    return retcode, stdout, stderr
Beispiel #7
0
def run_test_in_subprocess(testname, ns):
    ns_dict = vars(ns)
    worker_args = (ns_dict, testname)
    worker_args = json.dumps(worker_args)

    cmd = [
        sys.executable,
        *support.args_from_interpreter_flags(),
        '-u',  # Unbuffered stdout and stderr
        '-m',
        'test.regrtest',
        '--worker-args',
        worker_args
    ]
    if ns.pgo:
        cmd += ['--pgo']

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    return subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            universal_newlines=True,
                            close_fds=(os.name != 'nt'),
                            cwd=support.SAVEDCWD)
Beispiel #8
0
def run_test_in_subprocess(testname: str, ns: Namespace) -> subprocess.Popen:
    ns_dict = vars(ns)
    worker_args = (ns_dict, testname)
    worker_args = json.dumps(worker_args)
    if ns.python is not None:
        # The "executable" may be two or more parts, e.g. "node python.js"
        executable = shlex.split(ns.python)
    else:
        executable = [sys.executable]
    cmd = [*executable, *support.args_from_interpreter_flags(),
           '-u',    # Unbuffered stdout and stderr
           '-m', 'test.regrtest',
           '--worker-args', worker_args]

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    kw = {}
    if USE_PROCESS_GROUP:
        kw['start_new_session'] = True
    return subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            # bpo-45410: Write stderr into stdout to keep
                            # messages order
                            stderr=subprocess.STDOUT,
                            universal_newlines=True,
                            close_fds=(os.name != 'nt'),
                            cwd=os_helper.SAVEDCWD,
                            **kw)
Beispiel #9
0
def run_test_in_subprocess(testname: str, ns: Namespace, tmp_dir: str,
                           stdout_fh: TextIO) -> subprocess.Popen:
    ns_dict = vars(ns)
    worker_args = (ns_dict, testname)
    worker_args = json.dumps(worker_args)
    if ns.python is not None:
        executable = ns.python
    else:
        executable = [sys.executable]
    cmd = [
        *executable,
        *support.args_from_interpreter_flags(),
        '-u',  # Unbuffered stdout and stderr
        '-m',
        'test.regrtest',
        '--worker-args',
        worker_args
    ]

    env = dict(os.environ)
    if tmp_dir is not None:
        env['TMPDIR'] = tmp_dir
        env['TEMP'] = tmp_dir
        env['TMP'] = tmp_dir

    # Running the child from the same working directory as regrtest's original
    # invocation ensures that TEMPDIR for the child is the same when
    # sysconfig.is_python_build() is true. See issue 15300.
    kw = dict(
        env=env,
        stdout=stdout_fh,
        # bpo-45410: Write stderr into stdout to keep messages order
        stderr=stdout_fh,
        text=True,
        close_fds=(os.name != 'nt'),
        cwd=os_helper.SAVEDCWD,
    )
    if USE_PROCESS_GROUP:
        kw['start_new_session'] = True
    return subprocess.Popen(cmd, **kw)