import pytest
from hep_data_llm.usage_info import UsageInfo, sum_usage_infos


def test_sum_usage_infos_basic():
    infos = [
        UsageInfo("modelA", 1.0, 10, 20, 30, 0.01),
        UsageInfo("modelB", 2.0, 15, 25, 40, 0.02),
    ]
    result = sum_usage_infos(infos)
    assert result is not None
    assert result.model == "modelA,modelB"
    assert result.elapsed == 3.0
    assert result.prompt_tokens == 25
    assert result.completion_tokens == 45
    assert result.total_tokens == 70
    assert result.cost == 0.03


def test_sum_usage_infos_same_model():
    infos = [
        UsageInfo("gpt-5", 1.0, 10, 20, 30, 0.01),
        UsageInfo("gpt-5", 2.0, 15, 25, 40, 0.02),
    ]
    result = sum_usage_infos(infos)
    assert result is not None
    assert result.model == "gpt-5"
    assert result.elapsed == 3.0
    assert result.prompt_tokens == 25
    assert result.completion_tokens == 45
    assert result.total_tokens == 70
    assert result.cost == 0.03


def test_sum_usage_infos_none_tokens():
    infos = [
        UsageInfo("modelA", 1.0, None, 20, 30, 0.01),
        UsageInfo("modelB", 2.0, 15, 25, 40, 0.02),
    ]
    result = sum_usage_infos(infos)
    assert result is not None
    assert result.prompt_tokens == 15
    assert result.completion_tokens == 45
    assert result.total_tokens == 70
    assert result.cost == 0.03


def test_sum_usage_infos_empty():
    with pytest.raises(ValueError):
        sum_usage_infos([])
