Heray-Was-Here
Server : Apache
System : Linux vps43555.mylogin.co 3.10.0-1160.53.1.vz7.185.3 #1 SMP Tue Jan 25 12:49:12 MSK 2022 x86_64
User : redsea ( 60651)
PHP Version : 7.4.32
Disable Function : NONE
Directory :  /usr/local/python-3.9/lib/python3.9/site-packages/traitlets/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/python-3.9/lib/python3.9/site-packages/traitlets/tests/utils.py
import sys
from subprocess import PIPE, Popen


def get_output_error_code(cmd):
    """Get stdout, stderr, and exit code from running a command"""
    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()
    out = out.decode("utf8", "replace")  # type:ignore
    err = err.decode("utf8", "replace")  # type:ignore
    return out, err, p.returncode


def check_help_output(pkg, subcommand=None):
    """test that `python -m PKG [subcommand] -h` works"""
    cmd = [sys.executable, "-m", pkg]
    if subcommand:
        cmd.extend(subcommand)
    cmd.append("-h")
    out, err, rc = get_output_error_code(cmd)
    assert rc == 0, err
    assert "Traceback" not in err
    assert "Options" in out
    assert "--help-all" in out
    return out, err


def check_help_all_output(pkg, subcommand=None):
    """test that `python -m PKG --help-all` works"""
    cmd = [sys.executable, "-m", pkg]
    if subcommand:
        cmd.extend(subcommand)
    cmd.append("--help-all")
    out, err, rc = get_output_error_code(cmd)
    assert rc == 0, err
    assert "Traceback" not in err
    assert "Options" in out
    assert "Class options" in out
    return out, err

Hry