File: test_runsubprocess.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (41 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download | duplicates (9)
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
40
41
import py, os
from rpython.tool.runsubprocess import run_subprocess

def test_no_such_command():
    py.test.raises(EnvironmentError, run_subprocess,
                   'this_command_does_not_exist', [])
    py.test.raises(EnvironmentError, run_subprocess,
                   'this_command_does_not_exist', [])

def test_echo():
    if not os.path.exists('/bin/echo'):
        py.test.skip("there is no /bin/echo")
    returncode, stdout, stderr = run_subprocess('/bin/echo', 'FooBar')
    assert returncode == 0
    assert stdout == 'FooBar\n'
    assert stderr == ''

def test_false():
    if not os.path.exists('/bin/false'):
        py.test.skip("there is no /bin/false")
    returncode, stdout, stderr = run_subprocess('/bin/false', [])
    assert returncode == 1
    assert stdout == ''
    assert stderr == ''

def test_cat_fail():
    if not os.path.exists('/bin/cat'):
        py.test.skip("there is no /bin/cat")
    returncode, stdout, stderr = run_subprocess('/bin/cat', 'no/such/filename')
    assert returncode == 1
    assert stdout == ''
    assert 'no/such/filename' in stderr

def test_recover_lost_process():
    if not hasattr(os, 'fork'):
        py.test.skip("there is no os.fork()")
    from rpython.tool import runsubprocess
    import signal
    os.kill(runsubprocess._child.pid, signal.SIGTERM)
    runsubprocess._child.wait()
    test_echo()