Tests to_attributes with all attributes present.
(
usage_metadata: types.GenerateContentResponseUsageMetadata,
)
| 150 | |
| 151 | |
| 152 | def test_to_attributes_full( |
| 153 | usage_metadata: types.GenerateContentResponseUsageMetadata, |
| 154 | ): |
| 155 | """Tests to_attributes with all attributes present.""" |
| 156 | usage_metadata.prompt_token_count = 10 |
| 157 | usage_metadata.tool_use_prompt_token_count = 5 |
| 158 | usage_metadata.candidates_token_count = 20 |
| 159 | usage_metadata.thoughts_token_count = 8 |
| 160 | usage_metadata.cached_content_token_count = 100 |
| 161 | |
| 162 | token_usage = _token_usage.TokenUsage(usage_metadata) |
| 163 | attrs = token_usage.to_attributes() |
| 164 | assert attrs[_token_usage.GEN_AI_USAGE_INPUT_TOKENS] == 15 |
| 165 | assert attrs[_token_usage.GEN_AI_USAGE_OUTPUT_TOKENS] == 28 |
| 166 | assert attrs[_token_usage.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] == 100 |
| 167 | assert attrs[_token_usage.GEN_AI_USAGE_REASONING_OUTPUT_TOKENS] == 8 |
| 168 | |
| 169 | |
| 170 | def test_to_attributes_partial( |
nothing calls this directly
no test coverage detected