Example #1
0
def test_iter_timeout():
    with pytest.raises(TimeoutExpired):
        with Shell.create('python task.py', timeout=1) as command:
            for line in command:
                print(line)
            # duplicate close
            command.close()
        assert command.is_timeout == True
Example #2
0
async def test_async_iter():
    async with Shell.create('python task.py',
                            raise_on_stderr=False) as command:
        async for line in command:
            print(line)
        # duplicate close
        await command.aclose()
        assert command.has_errors == True
        assert command.is_closed == True
Example #3
0
async def test_timeout_async():
    with pytest.raises(TimeoutExpired) as e:
        async with Shell.create('python', timeout=1) as command:
            async for line in command:
                print(line)
        assert command.is_timeout == True
Example #4
0
async def test_raise_on_stderr_async():
    with pytest.raises(ShellError):
        async with Shell.create('foo', raise_on_stderr=True) as command:
            async for line in command:
                print(line)
Example #5
0
def test_create():
    shell = Shell.create('hostname')
    assert shell.read() == socket.gethostname()
Example #6
0
def test_command_error():
    with Shell.create('foo', raise_on_stderr=False) as command:
        for line in command:
            print(line)
    assert command.is_closed == True
    assert command.has_errors == True
Example #7
0
async def test_async_iter_break():
    async with Shell.create('python task.py', raise_on_stderr=False) as std:
        async for line in std:
            print(line)
            await std.aclose()
Example #8
0
def test_iter_break():
    with Shell.create('python task.py', timeout=1) as std:
        for output in std:
            print(output)
            std.close()
Example #9
0
def test_read_timeout():
    with pytest.raises(TimeoutExpired):
        with Shell.create('python task.py', timeout=1) as command:
            print(command.read())
Example #10
0
async def test_read_async():
    async with Shell.create('hostname') as command:
        hostname = await command.read_async()
        assert hostname == socket.gethostname()
        assert command.is_timeout == False
Example #11
0
def test_exec():
    hostname = Shell.exec('hostname')
    assert hostname == socket.gethostname()