示例#1
0
async def test_gen():
    coro = gen_function()

    result = get_coroutine_function_location(coro)
    assert result == ('asyncio.coroutines:gen_function')

    coro.close()
示例#2
0
async def test_coro():
    coro = coro_function()

    result = get_coroutine_function_location(coro)
    assert result == (
        'tests.test_aux_get_coroutine_function_location:coro_function')

    coro.close()
示例#3
0
async def test_unmatched_with_sys_path(monkeypatch, value):
    monkeypatch.setattr('sys.path', value)

    from async_reduce import aux
    importlib.reload(aux)

    coro = coro_function()

    result = aux.get_coroutine_function_location(coro)
    assert result == '<unknown module>:coro_function'

    coro.close()
示例#4
0
    def _auto_ident(coro: Coroutine[Any, Any, T_Result]) -> str:
        func_loc = get_coroutine_function_location(coro)

        try:
            hsh = hash(tuple(inspect.getcoroutinelocals(coro).items()))
        except TypeError:
            raise TypeError(
                'Unable to auto calculate identity for coroutine because using'
                ' unhashable arguments, you should set `ident` manual like:'
                '\n\tawait async_reduce({}(...), ident="YOU-IDENT-FOR-THAT")'
                ''.format(getattr(coro, '__name__')))

        return '{}(<state_hash:{}>)'.format(func_loc, hsh)
示例#5
0
 def on_exception_for(self, coro: Coroutine[Any, Any, Any], ident: str,
                      exception: Union[Exception, CancelledError]) -> None:
     self.errors[get_coroutine_function_location(coro)] += 1
示例#6
0
 def on_reducing_for(self, coro: Coroutine[Any, Any, Any],
                     ident: str) -> None:
     self.reduced[get_coroutine_function_location(coro)] += 1
示例#7
0
 def on_apply_for(self, coro: Coroutine[Any, Any, Any], ident: str) -> None:
     self.total[get_coroutine_function_location(coro)] += 1