import pytest

from utils.process import run, silent_run, RunError
from utils.fs import in_temp_dir


def test_run(capsys):
    with in_temp_dir():
        assert run('echo hello > hello.txt; echo world >> hello.txt', shell=True)

        out = run('ls', return_output=True)
        assert out == 'hello.txt\n'

        out = run(['cat', 'hello.txt'], return_output=True)
        assert out == 'hello\nworld\n'

        with pytest.raises(RunError):
            run('blah')

        assert not run('blah', raises=False)

        assert silent_run('ls -l')
        out, _ = capsys.readouterr()
        assert out == ''

[((8, 9, 8, 22), 'utils.fs.in_temp_dir', 'in_temp_dir', ({}, {}), '()', False, 'from utils.fs import in_temp_dir\n'), ((9, 15, 9, 81), 'utils.process.run', 'run', (), '', False, 'from utils.process import run, silent_run, RunError\n'), ((11, 14, 11, 43), 'utils.process.run', 'run', (), '', False, 'from utils.process import run, silent_run, RunError\n'), ((14, 14, 14, 59), 'utils.process.run', 'run', (), '', False, 'from utils.process import run, silent_run, RunError\n'), ((22, 15, 22, 34), 'utils.process.silent_run', 'silent_run', ({(22, 26, 22, 33): '"""ls -l"""'}, {}), "('ls -l')", False, 'from utils.process import run, silent_run, RunError\n'), ((17, 13, 17, 36), 'pytest.raises', 'pytest.raises', ({(17, 27, 17, 35): 'RunError'}, {}), '(RunError)', False, 'import pytest\n'), ((18, 12, 18, 23), 'utils.process.run', 'run', ({(18, 16, 18, 22): '"""blah"""'}, {}), "('blah')", False, 'from utils.process import run, silent_run, RunError\n'), ((20, 19, 20, 44), 'utils.process.run', 'run', (), '', False, 'from utils.process import run, silent_run, RunError\n')]