Skip to content

testing

Class info

🛈 DocStrings

Functions for tests.

We need some functions importable during the tests for proper testing.

analyze_ast async

analyze_ast(code: str) -> dict[str, int]

Analyze Python code AST.

Parameters:

Name Type Description Default
code str

Python source code to analyze

required

Returns:

Type Description
dict[str, int]

Dictionary with analysis results

Source code in src/llmling/testing/tools.py
async def analyze_ast(code: str) -> dict[str, int]:
    """Analyze Python code AST.

    Args:
        code: Python source code to analyze

    Returns:
        Dictionary with analysis results
    """
    tree = ast.parse(code)
    return {
        "classes": len([n for n in ast.walk(tree) if isinstance(n, ast.ClassDef)]),
        "functions": len([n for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)]),
    }

append_text

append_text(text: str, suffix: str = '!') -> str

Append suffix to text.

Source code in src/llmling/testing/processors.py
def append_text(text: str, suffix: str = "!") -> str:
    """Append suffix to text."""
    return f"{text}{suffix}"

async_reverse_text async

async_reverse_text(text: str) -> str

Reverse text asynchronously.

Source code in src/llmling/testing/processors.py
async def async_reverse_text(text: str) -> str:
    """Reverse text asynchronously."""
    await asyncio.sleep(0.1)  # Simulate async work
    return text[::-1]

example_tool async

example_tool(text: str, repeat: int = 1) -> str

Example tool that repeats text.

Parameters:

Name Type Description Default
text str

Text to repeat

required
repeat int

Number of times to repeat

1

Returns:

Type Description
str

The repeated text

Source code in src/llmling/testing/tools.py
async def example_tool(text: str, repeat: int = 1) -> str:
    """Example tool that repeats text.

    Args:
        text: Text to repeat
        repeat: Number of times to repeat

    Returns:
        The repeated text
    """
    return text * repeat

failing_processor async

failing_processor(text: str) -> str

Test helper that fails.

Source code in src/llmling/testing/processors.py
async def failing_processor(text: str) -> str:
    """Test helper that fails."""
    msg = "Test failure"
    raise ValueError(msg)

failing_tool async

failing_tool(text: str) -> str

Tool that always fails.

Source code in src/llmling/testing/tools.py
5
6
7
8
async def failing_tool(text: str) -> str:
    """Tool that always fails."""
    msg = "Intentional failure"
    raise ValueError(msg)

get_mcp_tools

get_mcp_tools()

Entry point exposing test tools to LLMling.

Source code in src/llmling/testing/__init__.py
def get_mcp_tools():
    """Entry point exposing test tools to LLMling."""
    from llmling.testing.tools import example_tool, analyze_ast

    return [example_tool, analyze_ast]

multiply

multiply(text: str, times: int = 2) -> str

Convert text to uppercase.

Source code in src/llmling/testing/processors.py
def multiply(text: str, times: int = 2) -> str:
    """Convert text to uppercase."""
    return text * times

reverse_text

reverse_text(text: str) -> str

Reverse input text.

Source code in src/llmling/testing/processors.py
4
5
6
def reverse_text(text: str) -> str:
    """Reverse input text."""
    return text[::-1]

uppercase_text

uppercase_text(text: str) -> str

Convert text to uppercase.

Source code in src/llmling/testing/processors.py
def uppercase_text(text: str) -> str:
    """Convert text to uppercase."""
    return text.upper()