/usr/lib/python3/dist-packages/traitlets/tests/utils.py is in python3-traitlets 4.3.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import sys
from subprocess import Popen, PIPE
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')
err = err.decode('utf8', 'replace')
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 parameters" in out
return out, err
|