コード例 #1
0
ファイル: test_utils.py プロジェクト: pixy25/purerpc
    def decorator(corofunc):
        if not inspect.iscoroutinefunction(corofunc):
            raise TypeError("Expected coroutine function")

        @forge.compose(
            forge.copy(corofunc),
            forge.modify(channel_arg_name,
                         name=port_fixture_name,
                         interface_name="port_fixture_value"),
        )
        async def new_corofunc(*, port_fixture_value, **kwargs):
            import purerpc
            async with purerpc.insecure_channel("127.0.0.1",
                                                port_fixture_value) as channel:
                await corofunc(**kwargs, channel=channel)

        return new_corofunc
コード例 #2
0
ファイル: test_utils.py プロジェクト: pixy25/purerpc
    def decorator(func):
        if hasattr(func, "__parallelized__") and func.__parallelized__:
            raise TypeError(
                "Cannot pass gRPC channel to already parallelized test, grpc_client_parallelize should "
                "be the last decorator in chain")

        @forge.compose(
            forge.copy(func),
            forge.modify(channel_arg_name,
                         name=port_fixture_name,
                         interface_name="port_fixture_value"),
        )
        def new_func(*, port_fixture_value, **kwargs):
            import grpc
            with grpc.insecure_channel(
                    '127.0.0.1:{}'.format(port_fixture_value)) as channel:
                func(**kwargs, channel=channel)

        return new_func
コード例 #3
0
import forge
import aiohttp
from typing import Dict, List, Union

# RestClient signature decorators

GET_SIGNATURE = forge.compose(
    forge.copy(aiohttp.ClientSession.get),
    forge.modify("url", default=None),
    forge.returns(aiohttp.ClientResponse),
    forge.insert(
        [
            forge.kwo("parameters",
                      default={},
                      type=Dict[str, Union[str, List[str]]]),
            forge.kwo("headers", default={}, type=Dict[str, str]),
        ],
        before=lambda arg: arg.kind == forge.FParameter.VAR_KEYWORD,
    ),
)

MGET_SIGNATURE = forge.compose(
    forge.copy(aiohttp.ClientSession.get, exclude="url"),
    forge.returns(List[aiohttp.ClientResponse]),
    forge.insert(
        forge.pok(
            "urls",
            type=forge.fsignature(aiohttp.ClientSession.get)["url"].type,
            default=None,
        ),
        index=1,