add support for async resources

This commit is contained in:
Michał Pstrąg
2025-01-18 19:37:39 +01:00
parent 4c71c6168f
commit f5f19b2361
3 changed files with 33 additions and 9 deletions

View File

@@ -120,3 +120,19 @@ class TestFunctionResource:
)
content = await resource.read()
assert isinstance(content, str)
@pytest.mark.anyio
async def test_async_read_text(self):
"""Test reading text from async FunctionResource."""
async def get_data() -> str:
return "Hello, world!"
resource = FunctionResource(
uri=AnyUrl("function://test"),
name="test",
fn=get_data,
)
content = await resource.read()
assert content == "Hello, world!"
assert resource.mime_type == "text/plain"