Debian Codegraph @

rpython/tool/test/test_runsubprocess.py

raw symbols SCIP
1 import py, os
2 from rpython.tool.runsubprocess import run_subprocess
3
4 def test_no_such_command():
5 py.test.raises(EnvironmentError, run_subprocess,
6 'this_command_does_not_exist', [])
7 py.test.raises(EnvironmentError, run_subprocess,
8 'this_command_does_not_exist', [])
9
10 def test_echo():
11 if not os.path.exists('/bin/echo'):
12 py.test.skip("there is no /bin/echo")
13 returncode, stdout, stderr = run_subprocess('/bin/echo', 'FooBar')
14 assert returncode == 0
15 assert stdout == 'FooBar\n'
16 assert stderr == ''
17
18 def test_false():
19 if not os.path.exists('/bin/false'):
20 py.test.skip("there is no /bin/false")
21 returncode, stdout, stderr = run_subprocess('/bin/false', [])
22 assert returncode == 1
23 assert stdout == ''
24 assert stderr == ''
25
26 def test_cat_fail():
27 if not os.path.exists('/bin/cat'):
28 py.test.skip("there is no /bin/cat")
29 returncode, stdout, stderr = run_subprocess('/bin/cat', 'no/such/filename')
30 assert returncode == 1
31 assert stdout == ''
32 assert 'no/such/filename' in stderr
33
34 def test_recover_lost_process():
35 if not hasattr(os, 'fork'):
36 py.test.skip("there is no os.fork()")
37 from rpython.tool import runsubprocess
38 import signal
39 os.kill(runsubprocess._child.pid, signal.SIGTERM)
40 runsubprocess._child.wait()
41 test_echo()