nat.test#
Submodules#
Classes#
A test runner that enables isolated testing of NAT tools without requiring |
Functions#
Convenience context manager for testing tools with mocked dependencies. |
Package Contents#
- class ToolTestRunner#
A test runner that enables isolated testing of NAT tools without requiring full workflow setup, LLMs, or complex dependencies.
Usage: >>> runner = ToolTestRunner() >>> # Test a tool with minimal setup >>> result = await runner.test_tool( … config_type=MyToolConfig, … config_params={“param1”: “value1”}, … input_data=”test input” … ) >>> # Test a tool with mocked dependencies >>> async with runner.with_mocks() as mock_builder: >>> mock_builder.mock_llm(“my_llm”, “mocked response”) >>> result = await runner.test_tool( … config_type=MyToolConfig, … config_params={“llm_name”: “my_llm”}, … input_data=”test input” … )
- _ensure_plugins_loaded()#
Ensure all plugins are loaded for tool registration.
- async test_tool(config_type: type[nat.data_models.function.FunctionBaseConfig], config_params: dict[str, Any] | None = None, input_data: Any = None, expected_output: Any = None, \*\*kwargs) Any#
Test a tool in isolation with minimal setup.
- Args:
config_type: The tool configuration class config_params: Parameters to pass to the config constructor input_data: Input data to pass to the tool expected_output: Expected output for assertion (optional) **kwargs: Additional parameters
- Returns:
The tool’s output
- Raises:
AssertionError: If expected_output is provided and doesn’t match ValueError: If tool registration or execution fails
- async with_mocks()#
Context manager that provides a mock builder for setting up dependencies.
Usage: >>> async with runner.with_mocks() as mock_builder: >>> mock_builder.mock_llm(“my_llm”, “mocked response”) >>> result = await runner.test_tool_with_builder( … config_type=MyToolConfig, … builder=mock_builder, … input_data=”test input” … )
- async test_tool_with_builder(
- config_type: type[nat.data_models.function.FunctionBaseConfig],
- builder: MockBuilder,
- config_params: dict[str, Any] | None = None,
- input_data: Any = None,
- expected_output: Any = None,
Test a tool with a pre-configured mock builder.
- Args:
config_type: The tool configuration class builder: Pre-configured MockBuilder with mocked dependencies config_params: Parameters to pass to the config constructor input_data: Input data to pass to the tool expected_output: Expected output for assertion (optional)
- Returns:
The tool’s output
- async with_mocked_dependencies()#
Convenience context manager for testing tools with mocked dependencies.
Usage: >>> async with with_mocked_dependencies() as (runner, mock_builder): >>> mock_builder.mock_llm(“my_llm”, “mocked response”) … result = await runner.test_tool_with_builder( … config_type=MyToolConfig, … builder=mock_builder, … input_data=”test input” … )