Testing Helpers
Helpers for testing an extension’s tools, without installing the extension.
An extension’s tests call its tools directly, with the settings they need, and without the database or an LLM:
from pydantic import SecretStr
from smarter.apps.llmtool.extension.testing import call_tool, tool_context
from weather.tools import GetWeather
class TestGetWeather(unittest.TestCase):
def test_unknown_place(self):
context = tool_context("weather", google_maps_api_key=SecretStr("test-key"))
with patch("weather.services.googlemaps.Client") as client:
client.return_value.geocode.return_value = []
result = call_tool(GetWeather, {"location": "Atlantis"}, context)
self.assertIn("Could not find Atlantis", result["error"])
Run an extension repository’s tests in a Smarter development container with
manage.py test_extension <path>, which puts the repository on sys.path, so that its tests
import its package by name.
- class smarter.apps.llmtool.extension.testing.TestSettings(**data)[source]
Bases:
BaseModelThe base class of the settings that
tool_context()builds.- model_config = {'arbitrary_types_allowed': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.apps.llmtool.extension.testing.call_tool(tool, arguments, context=None)[source]
Call a tool as the platform does: validate its arguments, run it, and turn its errors into results.
Unlike the platform, it runs the tool in the calling thread, without a timeout, and lets unexpected exceptions propagate, so that a test sees them.
- Parameters:
tool (
type[SmarterExtensionTool]) – The tool’s class.arguments (
dict|str) – The LLM’s arguments, as a dict or a JSON string.context (
ExtensionContext|None) – The context;tool_context()with no settings if omitted.
- Return type:
TypeAliasType- Returns:
The tool’s result, or
{"error": ...}for invalid arguments or anExtensionToolError.