Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Response:
{
"timezone": "Europe/Warsaw",
"datetime": "2024-01-01T13:00:00+01:00",
"day_of_week": "Monday",
"is_dst": false
}
```
Expand All @@ -232,15 +233,17 @@ Response:
{
"source": {
"timezone": "America/New_York",
"datetime": "2024-01-01T12:30:00-05:00",
"datetime": "2024-01-01T16:30:00-05:00",
"day_of_week": "Monday",
"is_dst": false
},
"target": {
"timezone": "Asia/Tokyo",
"datetime": "2024-01-01T12:30:00+09:00",
"datetime": "2024-01-02T06:30:00+09:00",
"day_of_week": "Tuesday",
"is_dst": false
},
"time_difference": "+13.0h",
"time_difference": "+14.0h"
}
```

Expand Down
30 changes: 30 additions & 0 deletions src/time/test/time_server_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

import json
from pathlib import Path

from freezegun import freeze_time
from mcp.shared.exceptions import McpError
import pytest
Expand All @@ -8,6 +11,33 @@
from mcp_server_time.server import TimeServer, get_local_tz


def readme_response_blocks():
readme = Path(__file__).parents[1] / "README.md"
blocks = []
for chunk in readme.read_text(encoding="utf-8").split("Response:\n```json\n")[1:]:
raw_json, _, _ = chunk.partition("\n```")
blocks.append(json.loads(raw_json))
return blocks


def test_readme_response_examples_match_server_output():
time_server = TimeServer()

with freeze_time("2024-01-01 12:00:00+00:00"):
current_time = time_server.get_current_time("Europe/Warsaw").model_dump()

with freeze_time("2024-01-01 12:00:00+00:00"):
converted_time = time_server.convert_time(
"America/New_York",
"16:30",
"Asia/Tokyo",
).model_dump()

readme_blocks = readme_response_blocks()
assert current_time in readme_blocks
assert converted_time in readme_blocks


@pytest.mark.parametrize(
"test_time,timezone,expected",
[
Expand Down
Loading