mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Fix tests
This commit is contained in:
parent
2b3e3ec360
commit
fae91fa2f6
2 changed files with 12 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ from typing import Any, Callable, Union
|
|||
import httpx
|
||||
import pydantic.json
|
||||
import pydantic_core
|
||||
from pydantic import Field
|
||||
from pydantic import Field, ValidationInfo
|
||||
|
||||
from fastmcp.resources.base import Resource
|
||||
|
||||
|
|
@ -91,6 +91,15 @@ class FileResource(Resource):
|
|||
raise ValueError("Path must be absolute")
|
||||
return path
|
||||
|
||||
@pydantic.field_validator("is_binary")
|
||||
@classmethod
|
||||
def set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool:
|
||||
"""Set is_binary based on mime_type if not explicitly set."""
|
||||
if is_binary:
|
||||
return True
|
||||
mime_type = info.data.get("mime_type", "text/plain")
|
||||
return not mime_type.startswith("text/")
|
||||
|
||||
async def read(self) -> Union[str, bytes]:
|
||||
"""Read the file content."""
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class TestResourceTemplate:
|
|||
assert template.uri_template == "test://{key}/{value}"
|
||||
assert template.name == "test"
|
||||
assert template.mime_type == "text/plain" # default
|
||||
assert template.fn == my_func
|
||||
test_input = {"key": "test", "value": 42}
|
||||
assert template.fn(**test_input) == my_func(**test_input)
|
||||
|
||||
def test_template_matches(self):
|
||||
"""Test matching URIs against a template."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue