Skip to content

test: add unit tests for tools module#587

Open
stanley1208 wants to merge 1 commit intogoogle-deepmind:mainfrom
stanley1208:test/tools-module-tests
Open

test: add unit tests for tools module#587
stanley1208 wants to merge 1 commit intogoogle-deepmind:mainfrom
stanley1208:test/tools-module-tests

Conversation

@stanley1208
Copy link
Copy Markdown

Summary

The tools module (gemma/gm/tools/) had zero test coverage. This PR adds 19 unit tests covering the Tool base class, Calculator, and OneShotToolManager.

Tests added (_tools_test.py — 19 tests)

Tool base class (3 tests):

  • test_tool_name: name property returns lowercase class name
  • test_tool_argnames: introspects call signature correctly
  • test_tool_call: basic call works with kwargs

Calculator (6 tests):

  • test_calculator_basic_arithmetic: +, -, *, /
  • test_calculator_compound_expression: 25 * 4 + 10 = 110
  • test_calculator_math_functions: sqrt, floor, ceil
  • test_calculator_trig_functions: sin(0), cos(0)
  • test_calculator_name: returns 'calculator'
  • test_calculator_argnames: returns ('expression',)

Tool manager (10 tests):

  • test_parse_tool_call_valid_json: parses valid JSON tool call
  • test_parse_tool_call_json_in_text: extracts JSON embedded in text
  • test_parse_tool_call_no_json: returns None for plain text
  • test_parse_tool_call_invalid_json: returns None for malformed JSON
  • test_format_tool_result: correct formatting
  • test_tool_manager_execute_calculator: end-to-end tool execution
  • test_tool_manager_no_tool_call: returns None for non-tool output
  • test_tool_manager_unknown_tool: handles unregistered tools gracefully
  • test_tool_manager_system_prompt_contains_tool: prompt includes tool info
  • test_tool_manager_name_to_tool: name-to-tool mapping works correctly

Test plan

  • All 19 tests pass (pytest -vv gemma/gm/tools/_tools_test.py)
  • Full test suite unaffected (new file only, no changes to existing code)

The tools module (gemma/gm/tools/) had zero test coverage. This adds 19 tests covering:

Tool base class (3 tests): name property, argnames introspection, call method

Calculator (6 tests): arithmetic, compound expressions, math/trig functions, name, argnames

Tool manager (10 tests): JSON parsing, text extraction, invalid input handling, tool execution, unknown tools, system prompt generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant