##// END OF EJS Templates
add help output tests to traitlets.tests.utils
Min RK -
Show More
@@ -0,0 +1,40 b''
1 import sys
2 import nose.tools as nt
3
4 from subprocess import Popen, PIPE
5
6 def get_output_error_code(cmd):
7 """Get stdout, stderr, and exit code from running a command"""
8 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
9 out, err = p.communicate()
10 out = out.decode('utf8', 'replace')
11 err = err.decode('utf8', 'replace')
12 return out, err, p.returncode
13
14
15 def check_help_output(pkg, subcommand=None):
16 """test that `python -m PKG [subcommand] -h` works"""
17 cmd = [sys.executable, '-m', pkg]
18 if subcommand:
19 cmd.extend(subcommand)
20 cmd.append('-h')
21 out, err, rc = get_output_error_code(cmd)
22 nt.assert_equal(rc, 0, err)
23 nt.assert_not_in("Traceback", err)
24 nt.assert_in("Options", out)
25 nt.assert_in("--help-all", out)
26 return out, err
27
28
29 def check_help_all_output(pkg, subcommand=None):
30 """test that `python -m PKG --help-all` works"""
31 cmd = [sys.executable, '-m', pkg]
32 if subcommand:
33 cmd.extend(subcommand)
34 cmd.append('--help-all')
35 out, err, rc = get_output_error_code(cmd)
36 nt.assert_equal(rc, 0, err)
37 nt.assert_not_in("Traceback", err)
38 nt.assert_in("Options", out)
39 nt.assert_in("Class parameters", out)
40 return out, err
General Comments 0
You need to be logged in to leave comments. Login now