60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Tests for timeout normalization utilities."""
|
|
|
|
import datetime
|
|
from typing import Any, cast
|
|
|
|
import pytest
|
|
|
|
from fastmcp.utilities.timeout import (
|
|
normalize_timeout_to_seconds,
|
|
normalize_timeout_to_timedelta,
|
|
)
|
|
|
|
|
|
class TestNormalizeTimeoutToSeconds:
|
|
def test_none_stays_none(self):
|
|
assert normalize_timeout_to_seconds(None) is None
|
|
|
|
def test_numeric_values_become_float_seconds(self):
|
|
assert normalize_timeout_to_seconds(3) == 3.0
|
|
assert normalize_timeout_to_seconds(2.5) == 2.5
|
|
|
|
def test_zero_values_disable_timeout(self):
|
|
assert normalize_timeout_to_seconds(0) is None
|
|
assert normalize_timeout_to_seconds(datetime.timedelta(seconds=0)) is None
|
|
|
|
def test_timedelta_becomes_seconds(self):
|
|
assert (
|
|
normalize_timeout_to_seconds(datetime.timedelta(milliseconds=250)) == 0.25
|
|
)
|
|
|
|
def test_invalid_type_raises_type_error(self):
|
|
with pytest.raises(TypeError, match="Invalid timeout type"):
|
|
normalize_timeout_to_seconds(cast(Any, "1"))
|
|
|
|
|
|
class TestNormalizeTimeoutToTimedelta:
|
|
def test_none_stays_none(self):
|
|
assert normalize_timeout_to_timedelta(None) is None
|
|
|
|
def test_timedelta_is_returned_unchanged(self):
|
|
timeout = datetime.timedelta(seconds=5)
|
|
assert normalize_timeout_to_timedelta(timeout) is timeout
|
|
|
|
def test_numeric_values_become_timedeltas(self):
|
|
assert normalize_timeout_to_timedelta(3) == datetime.timedelta(seconds=3)
|
|
assert normalize_timeout_to_timedelta(0.5) == datetime.timedelta(seconds=0.5)
|
|
|
|
def test_invalid_type_raises_type_error(self):
|
|
with pytest.raises(TypeError, match="Invalid timeout type"):
|
|
normalize_timeout_to_timedelta(cast(Any, "1"))
|