Skip to content

solidworks_mcp.selftest.runner

solidworks_mcp.selftest.runner

Run the selftest's areas in order and turn each into an AreaResult.

Classes

Area

Bases: Protocol

One part of the selftest: what it needs, and how it runs.

Methods:
run async
run(ctx: Context, checks: list[Check]) -> None

Call tools and append a check per value read back.

Parameters:

Name Type Description Default
ctx Context

The selftest context.

required
checks list[Check]

The area's checks, appended to.

required
Source code in src/solidworks_mcp/selftest/runner.py
async def run(self, ctx: Context, checks: list[Check]) -> None:
    """Call tools and append a check per value read back.

    Args:
        ctx: The selftest context.
        checks: The area's checks, appended to.
    """

AreaResult dataclass

AreaResult(name: str, outcome: Outcome, checks: list[Check] = list(), calls: list[str] = list(), note: str | None = None)

One area's outcome, its checks, the tools it called, and why if not PASS.

Attributes
passed_count property
passed_count: int

The number of checks that passed.

Check dataclass

Check(name: str, expected: Any, measured: Any, tolerance: Any = None, unit: str = '', passed: bool | None = None)

One value read back from SolidWorks against the hand calculation.

passed is None when the value could not be measured, which counts as a failure.

Context dataclass

Context(call: ToolCaller, folder: Path, files: dict[str, str] = dict())

What the areas share: the tool caller, the folder, and saved files.

Outcome

Bases: StrEnum

An area's result.

ToolFailed

ToolFailed(tool: str, message: str)

Bases: Exception

A tool call returned status: error.

Remember which tool failed and its message.

Parameters:

Name Type Description Default
tool str

The tool's name.

required
message str

The tool's error message.

required
Source code in src/solidworks_mcp/selftest/results.py
def __init__(self, tool: str, message: str) -> None:
    """Remember which tool failed and its message.

    Args:
        tool: The tool's name.
        message: The tool's error message.
    """
    super().__init__(f"{tool} failed: {message}")
    self.tool = tool
    self.message = message
Methods:

Functions:

run_areas async

run_areas(areas: Iterable[Area], ctx: Context) -> list[AreaResult]

Run each area, skipping one whose files an earlier area didn't save.

A tool error ends its area as FAIL with the tool's message; the checks made before it are kept. Any other exception propagates, so a bug in the selftest is never reported as a SolidWorks failure.

Parameters:

Name Type Description Default
areas Iterable[Area]

The areas, in order.

required
ctx Context

The selftest context.

required

Returns:

Type Description
list[AreaResult]

list[AreaResult]: One result per area, in order.

Source code in src/solidworks_mcp/selftest/runner.py
async def run_areas(areas: Iterable[Area], ctx: Context) -> list[AreaResult]:
    """Run each area, skipping one whose files an earlier area didn't save.

    A tool error ends its area as FAIL with the tool's message; the checks
    made before it are kept. Any other exception propagates, so a bug in
    the selftest is never reported as a SolidWorks failure.

    Args:
        areas: The areas, in order.
        ctx: The selftest context.

    Returns:
        list[AreaResult]: One result per area, in order.
    """
    results = []
    for area in areas:
        missing = [need for need in area.needs if need not in ctx.files]
        if missing:
            results.append(
                AreaResult(
                    area.name,
                    Outcome.SKIP,
                    note=f"needs the saved {' and '.join(missing)}",
                )
            )
            continue
        first_call = len(ctx.call.calls)
        checks: list[Check] = []
        note = None
        try:
            await area.run(ctx, checks)
        except ToolFailed as exc:
            note = str(exc)
        passed = note is None and bool(checks) and all(c.passed for c in checks)
        results.append(
            AreaResult(
                area.name,
                Outcome.PASS if passed else Outcome.FAIL,
                checks,
                ctx.call.calls[first_call:],
                note,
            )
        )
    return results