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
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
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
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)
def test_create(): shell = Shell.create('hostname') assert shell.read() == socket.gethostname()
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
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()
def test_iter_break(): with Shell.create('python task.py', timeout=1) as std: for output in std: print(output) std.close()
def test_read_timeout(): with pytest.raises(TimeoutExpired): with Shell.create('python task.py', timeout=1) as command: print(command.read())
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
def test_exec(): hostname = Shell.exec('hostname') assert hostname == socket.gethostname()