コード例 #1
0
def test_spawn_failure(command):
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = OSError('unknown program')
        with pytest.raises(SystemExit) as exc:
            print(main(['--'] + command))
        assert exc.value.code == 2
        popen.assert_called_once_with(command)
コード例 #2
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_spawn_failure(command):
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = OSError('unknown program')
        with pytest.raises(SystemExit) as exc:
            print(main(['--'] + command))
        assert exc.value.code == 2
        popen.assert_called_once_with(command)
コード例 #3
0
def test_forward_status(status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['--'] + command) == status
        popen.assert_called_once_with(command)
コード例 #4
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_change_working_directory(tempcwd, status, command, workdir):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-w', workdir, '--'] + command) == status
        popen.assert_called_once_with(command, cwd=workdir)
コード例 #5
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_forward_status(status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['--'] + command) == status
        popen.assert_called_once_with(command)
コード例 #6
0
def test_change_working_directory(tempcwd, status, command, workdir):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-w', workdir, '--'] + command) == status
        popen.assert_called_once_with(command, cwd=workdir)
コード例 #7
0
def test_redirect_stderr(tempcwd, status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-e', 'foo.txt', '--'] + command) == status
        popen.assert_called_once_with(command, stderr=mock.ANY)
    assert os.path.exists('foo.txt')
コード例 #8
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_implicit_argv(status, command):
    with mock.patch('sys.argv', ['runwith', '--'] + command):
        process = mock.MagicMock()
        process.returncode = status
        process.wait.return_value = process.returncode
        with mock.patch('subprocess.Popen') as popen:
            popen.side_effect = [process]
            assert main() == status
            popen.assert_called_once_with(command)
コード例 #9
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_redirect_stderr(tempcwd, status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-e', 'foo.txt', '--'] + command) == status
        popen.assert_called_once_with(command, stderr=mock.ANY)
    assert os.path.exists('foo.txt')
コード例 #10
0
def test_implicit_argv(status, command):
    with mock.patch('sys.argv', ['runwith', '--'] + command):
        process = mock.MagicMock()
        process.returncode = status
        process.wait.return_value = process.returncode
        with mock.patch('subprocess.Popen') as popen:
            popen.side_effect = [process]
            assert main() == status
            popen.assert_called_once_with(command)
コード例 #11
0
def test_redirect_stdin(tempcwd, status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with open('foo.txt', 'wb') as stream:
        stream.write(b'FOO')
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-i', 'foo.txt', '--'] + command) == status
        popen.assert_called_once_with(command, stdin=mock.ANY)
コード例 #12
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_redirect_stdin(tempcwd, status, command):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    with open('foo.txt', 'wb') as stream:
        stream.write(b'FOO')
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-i', 'foo.txt', '--'] + command) == status
        popen.assert_called_once_with(command, stdin=mock.ANY)
コード例 #13
0
def test_respect_timebox(status, command, timebox):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.side_effect = [process.returncode]
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-t', timebox, '--'] + command) == status
        popen.assert_called_once_with(command)
        process.wait.assert_called_once_with()
        process.send_signal.assert_not_called()
        process.terminate.assert_not_called()
コード例 #14
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_respect_timebox(status, command, timebox):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.side_effect = [process.returncode]
    with mock.patch('subprocess.Popen') as popen:
        popen.side_effect = [process]
        assert main(['-t', timebox, '--'] + command) == status
        popen.assert_called_once_with(command)
        process.wait.assert_called_once_with()
        process.send_signal.assert_not_called()
        process.terminate.assert_not_called()
コード例 #15
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_exceed_timebox_and_grace_time(status, command, timebox):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    thread = mock.MagicMock()
    thread.is_alive.side_effect = [True, True]
    thread.join.side_effect = [None, None, None]
    with mock.patch('threading.Thread') as T:
        T.side_effect = [thread]
        with mock.patch('subprocess.Popen') as P:
            P.side_effect = [process]
            assert main(['-t', timebox, '-g', '2s', '--'] + command) == status
            P.assert_called_once_with(command)
            T.assert_called_once()
            process.send_signal.assert_called_once_with(SIGKILL)
            process.terminate.assert_called_once()
コード例 #16
0
def test_exceed_timebox_and_grace_time(status, command, timebox):
    process = mock.MagicMock()
    process.returncode = status
    process.wait.return_value = process.returncode
    thread = mock.MagicMock()
    thread.is_alive.side_effect = [True, True]
    thread.join.side_effect = [None, None, None]
    with mock.patch('threading.Thread') as T:
        T.side_effect = [thread]
        with mock.patch('subprocess.Popen') as P:
            P.side_effect = [process]
            assert main(['-t', timebox, '-g', '2s', '--'] + command) == status
            P.assert_called_once_with(command)
            T.assert_called_once()
            process.send_signal.assert_called_once_with(SIGKILL)
            process.terminate.assert_called_once()
コード例 #17
0
ファイル: test_main.py プロジェクト: AndreLouisCaron/runwith
def test_run_without_args():
    with mock.patch('subprocess.Popen') as popen:
        with pytest.raises(SystemExit) as exc:
            print(main([]))
        assert exc.value.code == 2
        popen.assert_not_called()
コード例 #18
0
def test_run_without_args():
    with mock.patch('subprocess.Popen') as popen:
        with pytest.raises(SystemExit) as exc:
            print(main([]))
        assert exc.value.code == 2
        popen.assert_not_called()
コード例 #19
0
# -*- coding: utf-8 -*-

import sys

from runwith import main

if __name__ == '__main__':  # pragma: no cover
    sys.exit(main(sys.argv[1:]))
コード例 #20
0
ファイル: __main__.py プロジェクト: AndreLouisCaron/runwith
# -*- coding: utf-8 -*-


import sys

from runwith import main


if __name__ == '__main__':  # pragma: no cover
    sys.exit(main(sys.argv[1:]))