Ejemplo n.º 1
0
async def test_Process_object_wait_when_error():
    async def raise_error():
        raise ValueError("child-error")

    async with open_in_process(raise_error) as proc:
        await asyncio.wait_for(proc.wait(), timeout=2)
        assert isinstance(proc.error, ValueError)
Ejemplo n.º 2
0
async def test_Process_object_wait_for_result_when_error():
    async def raise_error():
        raise ValueError("child-error")

    async with open_in_process(raise_error) as proc:
        with pytest.raises(ValueError, match="child-error"):
            await asyncio.wait_for(proc.wait_result(), timeout=2)
Ejemplo n.º 3
0
async def test_Process_object_wait_for_pid():
    async def return7():
        return 7

    async with open_in_process(return7) as proc:
        await asyncio.wait_for(proc.wait_pid(), timeout=2)
        assert isinstance(proc.pid, int)
Ejemplo n.º 4
0
async def test_Process_object_wait_for_returncode():
    async def system_exit_123():
        raise SystemExit(123)

    async with open_in_process(system_exit_123) as proc:
        await asyncio.wait_for(proc.wait_returncode(), timeout=2)
        assert proc.returncode == 123
Ejemplo n.º 5
0
async def test_Process_object_wait_for_return_value():
    async def return7():
        return 7

    async with open_in_process(return7) as proc:
        await asyncio.wait_for(proc.wait_return_value(), timeout=2)
        assert proc.return_value == 7
Ejemplo n.º 6
0
async def test_Process_object_wait_for_result_when_return_value():
    async def return7():
        return 7

    async with open_in_process(return7) as proc:
        result = await asyncio.wait_for(proc.wait_result(), timeout=2)
        assert result == 7
        assert proc.error is None
async def test_open_proc_SIGINT_while_running():
    async def do_sleep_forever():
        while True:
            await asyncio.sleep(0)

    async with open_in_process(do_sleep_forever) as proc:
        proc.send_signal(signal.SIGINT)
    assert proc.returncode == 2
async def test_open_proc_invalid_function_call():
    async def takes_no_args():
        pass

    async with open_in_process(takes_no_args, 1, 2, 3) as proc:
        pass
    assert proc.returncode == 1
    assert isinstance(proc.error, TypeError)
async def test_open_in_proc_SIGTERM_while_running():
    async def do_sleep_forever():
        while True:
            await asyncio.sleep(0)

    async with open_in_process(do_sleep_forever) as proc:
        proc.terminate()
    assert proc.returncode == 15
async def test_open_proc_KeyboardInterrupt_while_running():
    async def do_sleep_forever():
        while True:
            await asyncio.sleep(0)

    with pytest.raises(KeyboardInterrupt):
        async with open_in_process(do_sleep_forever) as proc:
            raise KeyboardInterrupt
    assert proc.returncode == 2
async def test_open_in_proc_SIGKILL_while_running():
    async def do_sleep_forever():
        while True:
            await asyncio.sleep(0)

    async with open_in_process(do_sleep_forever) as proc:
        await proc.kill()
    assert proc.returncode == -9
    assert isinstance(proc.error, ProcessKilled)
async def test_open_proc_unpickleable_params(touch_path):
    async def takes_open_file(f):
        pass

    with pytest.raises(pickle.PickleError):
        with open(touch_path, "w") as touch_file:
            async with open_in_process(takes_open_file, touch_file):
                # this code block shouldn't get executed
                assert False
Ejemplo n.º 13
0
async def test_Process_object_state_api():
    async def return7():
        return 7

    async with open_in_process(return7) as proc:
        assert proc.state.is_on_or_after(State.STARTED)

        await asyncio.wait_for(proc.wait_for_state(State.FINISHED), timeout=2)
        assert proc.state is State.FINISHED
        assert proc.return_value == 7
async def test_open_proc_SIGINT_can_be_handled():
    async def do_sleep_forever():
        try:
            while True:
                await asyncio.sleep(0)
        except KeyboardInterrupt:
            return 9999

    async with open_in_process(do_sleep_forever) as proc:
        proc.send_signal(signal.SIGINT)
    assert proc.returncode == 0
    assert proc.result == 9999