tests/core/mcp/test_mcp_dispatcher_tree.py¶
Source from this local checkout, regenerated when the reader rebuilds.
Line links use #L<number>; a GitHub line range opens its first line.
1 # Copyright 2025 Softwell S.r.l.2 #3 # Licensed under the Apache License, Version 2.0 (the "License");4 # you may not use this file except in compliance with the License.5 # You may obtain a copy of the License at6 #7 # https://www.apache.org/licenses/LICENSE-2.08 #9 # Unless required by applicable law or agreed to in writing, software10 # distributed under the License is distributed on an "AS IS" BASIS,11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 # See the License for the specific language governing permissions and13 # limitations under the License.14 15 """Implementation test: the engine's method tree is a table, readable without a message.16 17 Photographs the shape of :class:`McpDispatcher` — the root routes, the18 ``tools`` branch and its class — and may be rewritten with it.19 """20 21 from __future__ import annotations22 23 from genro_asgi.mcp import McpDispatcher, McpEngine, McpTools24 25 26 class TestMcpDispatcherTree:27 def test_root_lists_ping_initialize_and_the_tools_branch(self) -> None:28 engine = McpEngine()29 nodes = engine.mcp_dispatcher.route.nodes()30 assert set(nodes["entries"]) == {"ping", "initialize"}31 assert set(nodes["routers"]["tools"]["entries"]) == {"list", "call"}32 33 def test_the_tools_branch_is_an_mcp_tools_reading_the_engine(self) -> None:34 engine = McpEngine()35 assert isinstance(engine.mcp_dispatcher, McpDispatcher)36 assert isinstance(engine.mcp_dispatcher.tools, McpTools)37 assert engine.mcp_dispatcher.tools.engine is engine38 39 def test_a_method_nobody_serves_resolves_to_not_found(self) -> None:40 engine = McpEngine()41 assert engine.mcp_dispatcher.route.node("resources/list").error == "not_found"42 assert engine.mcp_dispatcher.route.node("tools/nope").error == "not_found"