|
1 | 1 | import subprocess |
2 | 2 | import sys |
| 3 | +from types import ModuleType |
3 | 4 | from typing import Any |
4 | 5 |
|
5 | 6 | import mcp_types |
| 7 | +import mcp_types.jsonrpc |
| 8 | +import mcp_types.methods |
6 | 9 | import mcp_types.version |
7 | 10 | import pytest |
8 | 11 | from inline_snapshot import snapshot |
|
44 | 47 |
|
45 | 48 | import mcp |
46 | 49 | import mcp.types |
| 50 | +import mcp.types.jsonrpc |
| 51 | +import mcp.types.methods |
47 | 52 | import mcp.types.version |
48 | 53 |
|
49 | 54 |
|
@@ -455,10 +460,29 @@ def test_input_required_result_requires_at_least_one_of_input_requests_or_reques |
455 | 460 | assert InputRequiredResult(request_state="s").input_requests is None |
456 | 461 |
|
457 | 462 |
|
| 463 | +def _assert_mirrors(mirror: ModuleType, source: ModuleType) -> None: |
| 464 | + # The mirror shares the source's `__all__` list object by construction (`from source import |
| 465 | + # __all__`), so the meaningful proof is that every exported name is the identical object. |
| 466 | + assert all(getattr(mirror, name) is getattr(source, name) for name in source.__all__) |
| 467 | + |
| 468 | + |
458 | 469 | def test_mcp_types_namespace_mirrors_mcp_types_exactly(): |
459 | 470 | """SDK-defined: `mcp.types` is a permanent alias whose every name is the `mcp_types` object.""" |
460 | | - assert mcp.types.__all__ == mcp_types.__all__ |
461 | | - assert all(getattr(mcp.types, name) is getattr(mcp_types, name) for name in mcp_types.__all__) |
| 471 | + _assert_mirrors(mcp.types, mcp_types) |
| 472 | + |
| 473 | + |
| 474 | +@pytest.mark.parametrize( |
| 475 | + ("mirror", "source"), |
| 476 | + [ |
| 477 | + (mcp.types.jsonrpc, mcp_types.jsonrpc), |
| 478 | + (mcp.types.methods, mcp_types.methods), |
| 479 | + (mcp.types.version, mcp_types.version), |
| 480 | + ], |
| 481 | + ids=["jsonrpc", "methods", "version"], |
| 482 | +) |
| 483 | +def test_mcp_types_submodules_mirror_mcp_types_submodules_exactly(mirror: ModuleType, source: ModuleType): |
| 484 | + """SDK-defined: every supported `mcp_types` submodule has an `mcp.types` mirror, name for name.""" |
| 485 | + _assert_mirrors(mirror, source) |
462 | 486 |
|
463 | 487 |
|
464 | 488 | def test_mcp_types_attribute_access_names_the_replacement_for_a_removed_name(): |
@@ -505,11 +529,3 @@ def test_bare_import_mcp_binds_the_types_submodule(): |
505 | 529 | ) |
506 | 530 | assert result.returncode == 0, result.stderr |
507 | 531 | assert result.stdout == snapshot("Tool\n") |
508 | | - |
509 | | - |
510 | | -def test_mcp_types_version_mirrors_mcp_types_version_exactly(): |
511 | | - """SDK-defined: `mcp.types.version` is a permanent alias whose every name is the `mcp_types.version` object.""" |
512 | | - assert mcp.types.version.__all__ == mcp_types.version.__all__ |
513 | | - assert all( |
514 | | - getattr(mcp.types.version, name) is getattr(mcp_types.version, name) for name in mcp_types.version.__all__ |
515 | | - ) |
|
0 commit comments