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 == ''

[((133, 146), 'utils.fs.in_temp_dir', 'in_temp_dir', ([], {}), '()\n', (144, 146), False, 'from utils.fs import in_temp_dir\n'), ((163, 229), 'utils.process.run', 'run', (['"""echo hello > hello.txt; echo world >> hello.txt"""'], {'shell': '(True)'}), "('echo hello > hello.txt; echo world >> hello.txt', shell=True)\n", (166, 229), False, 'from utils.process import run, silent_run, RunError\n'), ((245, 274), 'utils.process.run', 'run', (['"""ls"""'], {'return_output': '(True)'}), "('ls', return_output=True)\n", (248, 274), False, 'from utils.process import run, silent_run, RunError\n'), ((326, 371), 'utils.process.run', 'run', (["['cat', 'hello.txt']"], {'return_output': '(True)'}), "(['cat', 'hello.txt'], return_output=True)\n", (329, 371), False, 'from utils.process import run, silent_run, RunError\n'), ((536, 555), 'utils.process.silent_run', 'silent_run', (['"""ls -l"""'], {}), "('ls -l')\n", (546, 555), False, 'from utils.process import run, silent_run, RunError\n'), ((425, 448), 'pytest.raises', 'pytest.raises', (['RunError'], {}), '(RunError)\n', (438, 448), False, 'import pytest\n'), ((462, 473), 'utils.process.run', 'run', (['"""blah"""'], {}), "('blah')\n", (465, 473), False, 'from utils.process import run, silent_run, RunError\n'), ((494, 519), 'utils.process.run', 'run', (['"""blah"""'], {'raises': '(False)'}), "('blah', raises=False)\n", (497, 519), False, 'from utils.process import run, silent_run, RunError\n')]