nat.test.tool_test_runner#
Attributes#
Classes#
A lightweight mock builder for tool testing that provides minimal dependencies. |
|
A test runner that enables isolated testing of NAT tools without requiring |
Functions#
Convenience context manager for testing tools with mocked dependencies. |
Module Contents#
- logger#
- class MockBuilder#
Bases:
nat.builder.builder.BuilderA lightweight mock builder for tool testing that provides minimal dependencies.
- _functions#
- _mocks#
- property sync_builder: nat.builder.sync_builder.SyncBuilder#
- mock_function_group(name: str, mock_response: Any)#
Add a mock function group that returns a fixed response.
- mock_memory_client(name: str, mock_response: Any)#
Add a mock memory client that returns a fixed response.
- mock_object_store(name: str, mock_response: Any)#
Add a mock object store that returns a fixed response.
- mock_ttc_strategy(name: str, mock_response: Any)#
Add a mock TTC strategy that returns a fixed response.
- mock_auth_provider(name: str, mock_response: Any)#
Add a mock auth provider that returns a fixed response.
- mock_trainer_adapter(name: str, mock_response: Any)#
Add a mock trainer adapter that returns a fixed response.
- mock_trajectory_builder(name: str, mock_response: Any)#
Add a mock trajectory builder that returns a fixed response.
- async add_ttc_strategy(
- name: str,
- config: nat.data_models.ttc_strategy.TTCStrategyBaseConfig,
Mock implementation (no‑op).
- async get_ttc_strategy(
- strategy_name: str,
- pipeline_type: nat.experimental.test_time_compute.models.stage_enums.PipelineTypeEnum,
- stage_type: nat.experimental.test_time_compute.models.stage_enums.StageTypeEnum,
Return a mock TTC strategy if one is configured.
- async get_ttc_strategy_config(
- strategy_name: str,
- pipeline_type: nat.experimental.test_time_compute.models.stage_enums.PipelineTypeEnum,
- stage_type: nat.experimental.test_time_compute.models.stage_enums.StageTypeEnum,
Mock implementation.
- async add_auth_provider(
- name: str,
- config: nat.data_models.authentication.AuthProviderBaseConfig,
Mock implementation (no‑op).
- async get_auth_provider(
- auth_provider_name: str,
Return a mock auth provider if one is configured.
- abstractmethod add_function(
- name: str,
- config: nat.data_models.function.FunctionBaseConfig,
- Async:
Mock implementation - not used in tool testing.
- async get_function(name: str) nat.builder.function.Function#
Return a mock function if one is configured.
- get_function_config(
- name: str,
Mock implementation.
- abstractmethod add_function_group(
- name: str,
- config: nat.data_models.function.FunctionGroupBaseConfig,
- Async:
Mock implementation - not used in tool testing.
- async get_function_group(name: str) nat.builder.function.FunctionGroup#
Return a mock function group if one is configured.
- get_function_group_config(
- name: str,
Mock implementation.
- async set_workflow( ) nat.builder.function.Function#
Mock implementation.
- get_workflow() nat.builder.function.Function#
Mock implementation.
- get_workflow_config() nat.data_models.function.FunctionBaseConfig#
Mock implementation.
- async get_tools(
- tool_names: collections.abc.Sequence[str],
- wrapper_type,
Mock implementation.
- get_llm_config(llm_name: str) nat.data_models.llm.LLMBaseConfig#
Mock implementation.
- get_embedder_config(
- embedder_name: str,
Mock implementation.
- async add_memory_client(
- name: str,
- config,
- async get_memory_client(
- memory_name: str,
Return a mock memory client if one is configured.
- get_memory_client_config(
- memory_name: str,
Mock implementation.
- async get_retriever(retriever_name: str, wrapper_type=None)#
Return a mock retriever if one is configured.
- async get_retriever_config(
- retriever_name: str,
Mock implementation.
- async add_object_store(
- name: str,
- config: nat.data_models.object_store.ObjectStoreBaseConfig,
Mock implementation for object store.
- async get_object_store_client(
- object_store_name: str,
Return a mock object store client if one is configured.
- get_object_store_config(
- object_store_name: str,
Mock implementation for object store config.
- get_user_manager()#
Mock implementation.
- get_function_dependencies(
- fn_name: str,
Mock implementation.
- get_function_group_dependencies(
- fn_name: str,
Mock implementation.
- async get_middleware(
- middleware_name: str | nat.data_models.component_ref.MiddlewareRef,
Mock implementation.
- get_middleware_config(
- middleware_name: str | nat.data_models.component_ref.MiddlewareRef,
Mock implementation.
- async add_middleware(
- name: str | nat.data_models.component_ref.MiddlewareRef,
- config: nat.data_models.middleware.FunctionMiddlewareBaseConfig,
Mock implementation.
- async add_trainer(
- name: str,
- config: nat.data_models.finetuning.TrainerConfig,
Mock implementation.
- async get_trainer(
- trainer_name: str,
- trajectory_builder: nat.finetuning.interfaces.trajectory_builder.TrajectoryBuilder,
- trainer_adapter: nat.finetuning.interfaces.trainer_adapter.TrainerAdapter,
Return a mock trainer if one is configured.
- async get_trainer_config(
- trainer_name: str,
Mock implementation.
- async add_trainer_adapter(
- name: str,
- config: nat.data_models.finetuning.TrainerAdapterConfig,
Mock implementation.
- async get_trainer_adapter(
- trainer_adapter_name: str,
Return a mock trainer adapter if one is configured.
- async get_trainer_adapter_config(
- trainer_adapter_name: str,
Mock implementation.
- async add_trajectory_builder(
- name: str,
- config: nat.data_models.finetuning.TrajectoryBuilderConfig,
Mock implementation.
- async get_trajectory_builder(
- trajectory_builder_name: str,
Return a mock trajectory builder if one is configured.
- async get_trajectory_builder_config(
- trajectory_builder_name: str,
Mock implementation.
- 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” … )