Skip to content

Add comprehensive unit tests for accounting module#11

Open
joshgreaves wants to merge 1 commit intomainfrom
add-accounting-tests
Open

Add comprehensive unit tests for accounting module#11
joshgreaves wants to merge 1 commit intomainfrom
add-accounting-tests

Conversation

@joshgreaves
Copy link
Contributor

@joshgreaves joshgreaves commented Jan 13, 2026

User description

Summary

  • Added comprehensive unit tests for the accounting.py module
  • Tests cover the martian_cost_list and get_llm_cost functions with extensive edge case coverage

What's Included

martian_cost_list function tests:

  • ✅ Successful fetching and parsing of model costs from the API
  • ✅ Caching behavior verification (function results are properly cached)
  • ✅ HTTP error handling (404, 500, etc.)
  • ✅ Network error handling (connection failures)
  • ✅ Invalid JSON response handling
  • ✅ Default client creation when none is provided

get_llm_cost function tests:

  • ✅ Basic cost calculation with prompt and completion tokens
  • ✅ Request charge calculation when applicable
  • ✅ Decimal precision maintenance for accurate cost tracking
  • ✅ Error handling for missing models in cost mapping
  • ✅ Error handling for completions with no usage information
  • ✅ None pricing fields treated as zero cost
  • ✅ Partial None pricing fields (some costs defined, others not)
  • ✅ Zero token edge case handling
  • ✅ Large token count calculations

Testing Approach

  • All tests use mocking to avoid external API calls
  • Uses pytest for test execution
  • Tests are isolated and can run independently
  • Cache is cleared between tests to ensure clean state

Test Coverage

The new test file src/ares/llms/accounting_test.py contains 18 test cases across 2 test classes, providing thorough coverage of both happy paths and error scenarios.

🤖 Generated with Claude Code


Generated description

Adds comprehensive unit tests for the accounting module, which is responsible for tracking and calculating costs for LLM operations within the ares system. Validates the martian_cost_list function for fetching model pricing and the get_llm_cost function for calculating LLM usage costs.

Latest Contributors(0)
UserCommitDate
This pull request is reviewed by Baz. Review like a pro on (Baz).

Implemented unit tests for the accounting module covering:
- `martian_cost_list` function: Tests for successful fetching, caching behavior,
  error handling (HTTP errors, network errors, invalid JSON), and default client creation
- `get_llm_cost` function: Tests for basic cost calculation, request charges,
  decimal precision, error handling (missing model, missing usage), None pricing fields,
  zero tokens, and large token counts

The tests use mocking to avoid external API calls and verify correct behavior
across various scenarios including edge cases and error conditions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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