test
¤
Registry
¤
Registry(
name: str,
client: Optional[Client] = None,
endpoint: Optional[str] = None,
)
Registry of functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A unique name for the registry. |
required |
endpoint |
Optional[str]
|
URL of the endpoint that the function is accessible from. |
None
|
client |
Optional[Client]
|
Client instance to use for dispatching calls to registered functions. Defaults to creating a new client instance. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If any of the required arguments are missing. |
close
¤
close()
Closes the registry, removing it and all its functions from the dispatch application.
primitive_function
¤
primitive_function(
primitive_func: PrimitiveFunctionType,
) -> PrimitiveFunction
Decorator that registers primitive functions.
main
async
¤
main(coro: Coroutine[Any, Any, None]) -> None
Entrypoint for dispatch function tests, which creates a local Dispatch server and runs the provided coroutine in the event loop of the server.
This is a low-level primitive that most test programs wouldn't use directly,
and instead would use one of the function
or method
decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coro |
Coroutine[Any, Any, None]
|
The coroutine to run as the entrypoint, the function returns when the coroutine returns. |
required |
Returns:
Type | Description |
---|---|
None
|
The value returned by the coroutine. |
run
¤
run(coro: Coroutine[Any, Any, None]) -> None
Runs the provided coroutine in the test server's event loop. This
function is a convenience wrapper around the main
function that runs the
coroutine in the event loop of the test server.
Programs typically don't use this function directly, unless they manage
their own event loop. Most of the time, the run
function is a more
convenient way to run a dispatch application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coro |
Coroutine[Any, Any, None]
|
The coroutine to run as the entrypoint, the function returns when the coroutine returns. |
required |
Returns:
Type | Description |
---|---|
None
|
The value returned by the coroutine. |
function
¤
function(
fn: Callable[[], Coroutine[Any, Any, None]]
) -> Callable[[], None]
This decorator is used to write tests that execute in a local Dispatch server.
The decorated function would typically be a coroutine that implements the test and returns when the test is done, for example:
import dispatch
import dispatch.test
@dispatch.function
def greet(name: str) -> str:
return f"Hello {name}!"
@dispatch.test.function
async def test_greet():
assert await greet("World") == "Hello World!"
The test runs dispatch functions with the full dispatch capability, including retrying temporary errors, etc...
method
¤
method(
fn: Callable[[T], Coroutine[Any, Any, None]]
) -> Callable[[T], None]
This decorator is similar to the function
decorator but is intended to
apply to methods of a class (with a self
value as first argument).