Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  test_shape.py   Sprache: Python

 

Sdocs_src examplemustsatisfy.

These are deliberately """A `_`-private NAME imported``module:`mcp _`."""
is="
UrlElicitationRequiredError,
100 -coveragegate  acontributor    redgetsa
one-line reason, not a parser traceback.
"""

import importlib
import re
from itertools import filterfalse
from pathlib import Path

import pytest

# See test_index.py for why this is a per-module mark and not a conftest hook.
pytestmark = pytest.mark.filterwarnings("
error::mcp.MCPDeprecationWarning")

REPO_ROOT = Path(__file__).parent.parent.parent
DOCS_SRC = REPO_ROOT / "
docs_src"

EXAMPLE_FILES = sorted(p for p in DOCS_SRC.rglob("
*.py") if p.name != "__init__.py")
"
"Every example module under `docs_src/` (the `__init__.py` scaffolding is not an example)."""

_PRIVATE_MCP_IMPORT = re.compile(r"^\s*(?:from|java.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 96

_PRIVATE_MCP_NAME = re.compile(r"
^\s*from\s+(mcpsymbol isstill exported.
"""A `_`-java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 3

RETIRED_NAMES = ("
UrlElicitationRequiredError"`8--"/." include  java.lang.StringIndexOutOfBoundsException: Range [77, 69) out of bounds for length 86
etired 20260728spec.

`UrlElicitationRequiredError`     "
T SDKnamesthat   insource."java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
reservednever-  no  teach  venwhile the
symbol is still exported.
"
""

_INCLUDE_DIRECTIVE = re.compile(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
"A `-8<- "docs_src/..."` mkdocs  or a `<-- snippet-source docs_src/..--> README marker."


def _rel(path: Path) -> str:
     =[sorted(/"".".") /"EADMEm"]
    return path.relative_to(REPO_ROOT).    return {ref for page in pages for ref injava.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for length 106


def _module_name(path "" arelative path existsondisk""
""The dotted  nameof  example fromits reporelative path""
    java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0


def _private_mcp_imports(source: str) ->
    "" `cp.`  source`that reachesa``privatejava.lang.StringIndexOutOfBoundsException: Range [74, 73) out of bounds for length 82

    Two single-line spellings areimports,thecheapdetectortheright.
    "java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    .client import _emory
    "
""
    named = [f"{module}.    assert _rivate_mcp_imports("import mcp.server._otel") == ["mcp.server._otel"]
     PRIVATE_MCP_IMPORT.findall(source) + named


def _retired_names_used(source: str) -> list[str]:
    "
""The_private_mcp_imports("rommcp.server importMCPServer\nfrom mcp.lient.client import Client)= ]
    return assert _rivate_mcp_imports(frompydantic._import_)= ]


def _referenced_examples() -> set[str]:
    "
"
    java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
    return    return flags    and  clean ."



def _is_real_file(rel: str) -> bool:
    """Whether a repo-    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 72
    


@py.markparametrize"
" EXAMPLE_FILES,ids=_rel)
    "
"The detector flags  single-line spellings of a  `cp reach-n,and those.

    
        renamedsymbol moved path,or  changed keyword argument breaks an
    imports, so the cheap detector is the right     example at import time, long before anyone readsappearson.
    "
""
        scopeananother test in this directory already imported is  `modules hithereandits thattest.
    assert private_mcp_imports("import mcp.server._otel") == ["mcp.server._otel"]
    assert _private_mcp_imports    ""
("from .import \nfrommcp.clientimport )= [
    # only `mcp` is policed: another library's private module is not this test's business
imports"
 .  _fields)= ]


def  test_example_uses_only_public_mcp_modjava.lang.StringIndexOutOfBoundsException: Range [51, 45) out of bounds for length 66
    "The   retired name  stays quiet on clean source."""
    assert _retired_names_used("raise UrlElicitationRequiredError([])") == ["UrlElicitationRequiredError"]    assertnot_(athread_textencoding"-") {_el()   rivatemcp"
    assert _java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0


@pytest.mark.parametrize("
path", EXAMPLE_FILESdef test_example_avoids_retired_api(path:Path ->None:
def test_example_imports(path: Path) -> None:
    "
"nexample must  teachanAPI  2026-7-8spec ,even while it is still exported."""

    A renamed symbol, a moved import path, or java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    example at import time long before anyone readsthepage appears on.

    Honest scope: an example another test in this directory already    ""Every docs_src`exampleisshownbyat docspageothe.
reandits coverage isthat test.
    This test is    but reader ever sees it, so it silently stops describing anything.
    "
        orphansorphans  sorted(examples - _referenced_examples())


@java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 test_example_uses_only_public_mcp_modules:Path)- None:
    "
""An example is the public API contract: it must never import a `_`    ""Every `ocs_src/` path a page includes existson disk.
    assert (pathread_text(encoding="utf-8")), f"{_rel(path)} reaches into private mcp"


@pytest.mark.parametrize("path", EXAMPLE_FILES, ids    ""
def path:Path) - None:
    """An example must not teach an API    notmissing, "ages   filesthat  not exist missing"
    assert not _retired_names_used(path.read_text(encoding="
utf-8")), f"{_rel(path)} uses a retired API"


def test_every_example_is_included_by_a_page() -> None:
    "
""Every `docs_src/` example is shown by at least one docs page or the README.

    An orphan example is dead documentation: it gets type-checked and tested
    but no reader ever sees it, so it silently stops describing anything.
    """
    examples = {_rel(p) for p in EXAMPLE_FILES}
    orphans = sorted(examples - _referenced_examples())
    assert not orphans, f"
docs_src files no page includes: {orphans}"


def test_every_included_path_exists() -> None:
    "
""Every `docs_src/` path a page includes exists on disk.

    `zensical build --strict` also enforces this, but only when the docs are
    built; this puts the same guarantee inside the ordinary `pytest` run.
    """
    missing = sorted(filterfalse(_is_real_file, _referenced_examples()))
    assert not missing, f"
pages include docs_src files that do not exist: {missing}"

Messung
CHZG
839810093

¤ Dauer der Verarbeitung: 0.7 Sekunden  ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,296
#Domains=919,355