def test_chained_procs(): ls = Process('ls {test_dir}'.format(test_dir=TEST_DIR)) grep = Process('grep 2') chain = ls | grep chain.run() assert chain.returncode == 0 assert chain.stdout.strip() == 'file2'
def test_multi_chained_procs(): ls = Process('ls {test_dir}'.format(test_dir=TEST_DIR)) grep = Process('grep 2') wc = Process('wc -c') chain = ls | grep | wc chain.run() assert chain.returncode == 0 assert chain.stdout.strip() == '6'
def tests_repr(): p = Process('foo') assert repr(p) == '<Process: foo>'
def test_not_ok_if_returncode_not_0(): assert not os.path.exists('/bin/nosuchcommand') p = Process('/bin/nosuchcommand') p.run() assert p.ok is False
def test_ok_if_returncode_0(): p = Process('ls') p.run() assert p.ok is True
def test_returncode(): assert not os.path.exists('/bin/nosuchcommand') p = Process('/bin/nosuchcommand') p.run() assert p.returncode == 127
def test_empty_output(): cat = Process('cat /dev/null') cat.run() assert cat.stdout == u''
def test_single_proc(): ls = Process('ls {test_dir}'.format(test_dir=TEST_DIR)) ls.run() assert ls.returncode == 0 assert ls.stdout == u'file1\nfile2\nfile3\n'