sherpa_ai.test_utils package#

Overview#

The test_utils package provides testing utilities to streamline and standardize test development for the Sherpa AI framework. It includes tools for managing test data files, working with both real and mock language models, and configuring logging for test environments.

Key Components

  • Data Utilities: Tools for locating and loading test data files

  • LLM Mocking: Utilities for creating fake LLMs with predetermined responses

  • Logging Utilities: Tools for configuring logging in test environments

Example Usage#

import pytest
from sherpa_ai.test_utils.data import get_test_data_file_path
from sherpa_ai.test_utils.llms import get_llm
from sherpa_ai.test_utils.loggers import config_logger_level

# Test using data utilities
def test_with_data_file(get_test_data_file_path):
    data_path = get_test_data_file_path(__file__, "test_data.json")
    # Use the data path in the test...

# Test using fake LLMs
@pytest.mark.parametrize("external_api", [False])
def test_with_llm(get_llm):
    llm = get_llm(__file__, "test_agent_response")
    response = llm.invoke("What is AI?")
    assert "intelligence" in response.content.lower()

# Test with custom logging
def test_with_logging(config_logger_level):
    config_logger_level("DEBUG")
    # Test will now log at DEBUG level

Submodules#

Module

Description

sherpa_ai.test_utils.data

Utilities for locating and loading test data files relative to test files.

sherpa_ai.test_utils.llms

Tools for creating both real and fake language models for testing.

sherpa_ai.test_utils.loggers

Utilities for configuring and isolating logging in test environments.

sherpa_ai.test_utils.data module#

sherpa_ai.test_utils.llms module#

sherpa_ai.test_utils.loggers module#

Module contents#